|
1 | 1 | var Class = require('../utils/Class'); |
2 | 2 |
|
3 | | -// Phaser.Animations.AnimationFrame |
4 | | - |
5 | 3 | var AnimationFrame = new Class({ |
6 | 4 |
|
7 | 5 | initialize: |
8 | 6 |
|
9 | 7 | /** |
10 | | - * [description] |
| 8 | + * A single frame in an Animation sequence. |
| 9 | + * |
| 10 | + * An AnimationFrame consists of a reference to the Texture it uses for rendering, references to other |
| 11 | + * frames in the animation, and index data. It also has the ability to fire its own `onUpdate` callback |
| 12 | + * and modify the animation timing. |
| 13 | + * |
| 14 | + * AnimationFrames are generated automatically by the Animation class. |
11 | 15 | * |
12 | 16 | * @class AnimationFrame |
13 | | - * @memberOf Phaser.Animations.AnimationFrame |
| 17 | + * @memberOf Phaser.Animations |
14 | 18 | * @constructor |
15 | 19 | * @since 3.0.0 |
16 | 20 | * |
17 | | - * @param {undefined} textureKey - [description] |
18 | | - * @param {undefined} textureFrame - [description] |
19 | | - * @param {undefined} index - [description] |
20 | | - * @param {undefined} frame - [description] |
| 21 | + * @param {string} textureKey - The key of the Texture this AnimationFrame uses. |
| 22 | + * @param {string|integer} textureFrame - The key of the Frame within the Texture that this AnimationFrame uses. |
| 23 | + * @param {integer} index - The index of this AnimationFrame within the Animation sequence. |
| 24 | + * @param {Phaser.Textures.Frame} frame - A reference to the Texture Frame this AnimationFrame uses for rendering. |
21 | 25 | */ |
22 | 26 | function AnimationFrame (textureKey, textureFrame, index, frame) |
23 | 27 | { |
24 | | - // The keys into the Texture Manager of the texture + frame this uses |
25 | | - |
26 | 28 | /** |
27 | | - * [description] |
| 29 | + * The key of the Texture this AnimationFrame uses. |
28 | 30 | * |
29 | 31 | * @property {string} textureKey |
| 32 | + * @since 3.0.0 |
30 | 33 | */ |
31 | 34 | this.textureKey = textureKey; |
32 | 35 |
|
33 | 36 | /** |
34 | | - * [description] |
| 37 | + * The key of the Frame within the Texture that this AnimationFrame uses. |
35 | 38 | * |
36 | | - * @property {Phaser.Textures.Frame} textureFrame |
| 39 | + * @property {string|integer} textureFrame |
| 40 | + * @since 3.0.0 |
37 | 41 | */ |
38 | 42 | this.textureFrame = textureFrame; |
39 | 43 |
|
40 | | - // The index of this frame within the Animation.frames array |
41 | | - |
42 | 44 | /** |
43 | | - * [description] |
| 45 | + * The index of this AnimationFrame within the Animation sequence. |
44 | 46 | * |
45 | 47 | * @property {integer} index |
| 48 | + * @since 3.0.0 |
46 | 49 | */ |
47 | 50 | this.index = index; |
48 | 51 |
|
49 | | - // Texture Frame |
50 | | - |
51 | 52 | /** |
52 | | - * [description] |
| 53 | + * A reference to the Texture Frame this AnimationFrame uses for rendering. |
53 | 54 | * |
54 | 55 | * @property {Phaser.Textures.Frame} frame |
| 56 | + * @since 3.0.0 |
55 | 57 | */ |
56 | 58 | this.frame = frame; |
57 | 59 |
|
58 | | - // Read-only |
59 | | - |
60 | 60 | /** |
61 | | - * [description] |
| 61 | + * Is this the first frame in an animation sequence? |
62 | 62 | * |
63 | 63 | * @property {boolean} isFirst |
64 | 64 | * @default false |
| 65 | + * @readOnly |
| 66 | + * @since 3.0.0 |
65 | 67 | */ |
66 | 68 | this.isFirst = false; |
67 | 69 |
|
68 | | - // Read-only |
69 | | - |
70 | 70 | /** |
71 | | - * [description] |
| 71 | + * Is this the last frame in an animation sequence? |
72 | 72 | * |
73 | 73 | * @property {boolean} isLast |
74 | 74 | * @default false |
| 75 | + * @readOnly |
| 76 | + * @since 3.0.0 |
75 | 77 | */ |
76 | 78 | this.isLast = false; |
77 | 79 |
|
78 | | - // The frame that comes before this one in the animation (if any) |
79 | | - // Read-only |
80 | | - |
81 | 80 | /** |
82 | | - * [description] |
| 81 | + * A reference to the AnimationFrame that comes before this one in the animation, if any. |
83 | 82 | * |
84 | | - * @property {?[type]} prevFrame |
| 83 | + * @property {?Phaser.Animations.AnimationFrame} prevFrame |
85 | 84 | * @default null |
| 85 | + * @readOnly |
| 86 | + * @since 3.0.0 |
86 | 87 | */ |
87 | 88 | this.prevFrame = null; |
88 | 89 |
|
89 | | - // The frame that comes after this one in the animation (if any) |
90 | | - // Read-only |
91 | | - |
92 | 90 | /** |
93 | | - * [description] |
| 91 | + * A reference to the AnimationFrame that comes after this one in the animation, if any. |
94 | 92 | * |
95 | | - * @property {?[type]} nextFrame |
| 93 | + * @property {?Phaser.Animations.AnimationFrame} nextFrame |
96 | 94 | * @default null |
| 95 | + * @readOnly |
| 96 | + * @since 3.0.0 |
97 | 97 | */ |
98 | 98 | this.nextFrame = null; |
99 | 99 |
|
100 | | - // Additional time (in ms) this frame should appear for - added onto the msPerFrame |
101 | | - |
102 | 100 | /** |
103 | | - * [description] |
| 101 | + * Additional time (in ms) that this frame should appear for during playback. |
| 102 | + * The value is added onto the msPerFrame set by the animation. |
104 | 103 | * |
105 | 104 | * @property {number} duration |
106 | 105 | * @default 0 |
| 106 | + * @since 3.0.0 |
107 | 107 | */ |
108 | 108 | this.duration = 0; |
109 | 109 |
|
110 | | - // What % through the animation progress is this frame? |
111 | | - // Read-only |
112 | | - |
113 | 110 | /** |
114 | | - * [description] |
| 111 | + * What % through the animation does this frame come? |
| 112 | + * This value is generated when the animation is created and cached here. |
115 | 113 | * |
116 | 114 | * @property {number} progress |
117 | 115 | * @default 0 |
| 116 | + * @readOnly |
| 117 | + * @since 3.0.0 |
118 | 118 | */ |
119 | 119 | this.progress = 0; |
120 | 120 |
|
121 | | - // Callback if this frame gets displayed |
122 | | - |
123 | 121 | /** |
124 | | - * [description] |
| 122 | + * A frame specific callback, invoked if this frame gets displayed and the callback is set. |
125 | 123 | * |
126 | | - * @property {?[type]} onUpdate |
| 124 | + * @property {?function} onUpdate |
127 | 125 | * @default null |
| 126 | + * @since 3.0.0 |
128 | 127 | */ |
129 | 128 | this.onUpdate = null; |
130 | | - |
131 | | - // When this frame hits, set sprite.visible to this |
132 | | - |
133 | | - /** |
134 | | - * [description] |
135 | | - * |
136 | | - * @property {boolean} setVisible |
137 | | - * @default false |
138 | | - */ |
139 | | - this.setVisible = false; |
140 | | - |
141 | | - this.visible = false; |
142 | 129 | }, |
143 | 130 |
|
| 131 | + /** |
| 132 | + * Generates a JavaScript object suitable for converting to JSON. |
| 133 | + * |
| 134 | + * @method Phaser.Animations.AnimationFrame#toJSON |
| 135 | + * @since 3.0.0 |
| 136 | + * |
| 137 | + * @return {object} The AnimationFrame data. |
| 138 | + */ |
144 | 139 | toJSON: function () |
145 | 140 | { |
146 | 141 | return { |
147 | 142 | key: this.textureKey, |
148 | 143 | frame: this.textureFrame, |
149 | | - duration: this.duration, |
150 | | - visible: this.visible |
| 144 | + duration: this.duration |
151 | 145 | }; |
152 | 146 | }, |
153 | 147 |
|
| 148 | + /** |
| 149 | + * Destroys this object by removing references to external resources and callbacks. |
| 150 | + * |
| 151 | + * @method Phaser.Animations.AnimationFrame#destroy |
| 152 | + * @since 3.0.0 |
| 153 | + */ |
154 | 154 | destroy: function () |
155 | 155 | { |
156 | 156 | this.frame = undefined; |
|
0 commit comments