Skip to content

Commit cee9ca0

Browse files
committed
Improved docs
1 parent 66f4ab6 commit cee9ca0

1 file changed

Lines changed: 60 additions & 13 deletions

File tree

src/gameobjects/sprite/Sprite.js

Lines changed: 60 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,12 @@ var Sprite = new Class({
136136
/**
137137
* Start playing the given animation on this Sprite.
138138
*
139-
* Animations in Phaser belong to the global Animation Manager. This means multiple Sprites can all play the same
140-
* animation. The following code shows how to create a global repeating animation. The animation will be created
139+
* Animations in Phaser can either belong to the global Animation Manager, or specifically to this Sprite.
140+
*
141+
* The benefit of a global animation is that multiple Sprites can all play the same animation, without
142+
* having to duplicate the data. You can just create it once and then play it on any Sprite.
143+
*
144+
* The following code shows how to create a global repeating animation. The animation will be created
141145
* from all of the frames within the sprite sheet that was loaded with the key 'muybridge':
142146
*
143147
* ```javascript
@@ -148,10 +152,15 @@ var Sprite = new Class({
148152
* repeat: -1
149153
* };
150154
*
155+
* // This code should be run from within a Scene:
151156
* this.anims.create(config);
152157
* ```
153158
*
154-
* With the animation created, you can now play it on this Sprite:
159+
* However, if you wish to create an animation that is unique to this Sprite, and this Sprite alone,
160+
* you can call the `Animation.create` method instead. It accepts the exact same parameters as when
161+
* creating a global animation, however the resulting data is kept locally in this Sprite.
162+
*
163+
* With the animation created, either globally or locally, you can now play it on this Sprite:
155164
*
156165
* ```javascript
157166
* this.add.sprite(x, y).play('run');
@@ -164,6 +173,13 @@ var Sprite = new Class({
164173
* this.add.sprite(x, y).play({ key: 'run', frameRate: 24 });
165174
* ```
166175
*
176+
* When playing an animation on a Sprite it will first check to see if it can find a matching key
177+
* locally within the Sprite. If it can, it will play the local animation. If not, it will then
178+
* search the global Animation Manager and look for it there.
179+
*
180+
* If you need a Sprite to be able to play both local and global animations, make sure they don't
181+
* have conflicting keys.
182+
*
167183
* See the documentation for the `PlayAnimationConfig` config object for more details about this.
168184
*
169185
* Also, see the documentation in the Animation Manager for further details on creating animations.
@@ -185,10 +201,14 @@ var Sprite = new Class({
185201
},
186202

187203
/**
188-
* Start playing the given animation on this Sprite in reverse.
204+
* Start playing the given animation on this Sprite, in reverse.
205+
*
206+
* Animations in Phaser can either belong to the global Animation Manager, or specifically to this Sprite.
207+
*
208+
* The benefit of a global animation is that multiple Sprites can all play the same animation, without
209+
* having to duplicate the data. You can just create it once and then play it on any Sprite.
189210
*
190-
* Animations in Phaser belong to the global Animation Manager. This means multiple Sprites can all play the same
191-
* animation. The following code shows how to create a global repeating animation. The animation will be created
211+
* The following code shows how to create a global repeating animation. The animation will be created
192212
* from all of the frames within the sprite sheet that was loaded with the key 'muybridge':
193213
*
194214
* ```javascript
@@ -199,10 +219,15 @@ var Sprite = new Class({
199219
* repeat: -1
200220
* };
201221
*
222+
* // This code should be run from within a Scene:
202223
* this.anims.create(config);
203224
* ```
204225
*
205-
* With the animation created, you can now play it on this Sprite:
226+
* However, if you wish to create an animation that is unique to this Sprite, and this Sprite alone,
227+
* you can call the `Animation.create` method instead. It accepts the exact same parameters as when
228+
* creating a global animation, however the resulting data is kept locally in this Sprite.
229+
*
230+
* With the animation created, either globally or locally, you can now play it on this Sprite:
206231
*
207232
* ```javascript
208233
* this.add.sprite(x, y).playReverse('run');
@@ -215,6 +240,13 @@ var Sprite = new Class({
215240
* this.add.sprite(x, y).playReverse({ key: 'run', frameRate: 24 });
216241
* ```
217242
*
243+
* When playing an animation on a Sprite it will first check to see if it can find a matching key
244+
* locally within the Sprite. If it can, it will play the local animation. If not, it will then
245+
* search the global Animation Manager and look for it there.
246+
*
247+
* If you need a Sprite to be able to play both local and global animations, make sure they don't
248+
* have conflicting keys.
249+
*
218250
* See the documentation for the `PlayAnimationConfig` config object for more details about this.
219251
*
220252
* Also, see the documentation in the Animation Manager for further details on creating animations.
@@ -245,6 +277,10 @@ var Sprite = new Class({
245277
*
246278
* If no animation is currently running, the given one begins after the delay.
247279
*
280+
* When playing an animation on a Sprite it will first check to see if it can find a matching key
281+
* locally within the Sprite. If it can, it will play the local animation. If not, it will then
282+
* search the global Animation Manager and look for it there.
283+
*
248284
* Prior to Phaser 3.50 this method was called 'delayedPlay'.
249285
*
250286
* @method Phaser.GameObjects.Components.Animation#playAfterDelay
@@ -264,13 +300,18 @@ var Sprite = new Class({
264300
},
265301

266302
/**
267-
* Waits for the current animation to complete one 'repeat' cycle, then starts playback of the given animation.
303+
* Waits for the current animation to complete the `repeatCount` number of repeat cycles, then starts playback
304+
* of the given animation.
268305
*
269-
* You can use this to ensure there are no harsh 'jumps' between two sets of animations, i.e. going from an
270-
* idle animation to a walking animation.
306+
* You can use this to ensure there are no harsh jumps between two sets of animations, i.e. going from an
307+
* idle animation to a walking animation, by making them blend smoothly into each other.
271308
*
272309
* If no animation is currently running, the given one will start immediately.
273310
*
311+
* When playing an animation on a Sprite it will first check to see if it can find a matching key
312+
* locally within the Sprite. If it can, it will play the local animation. If not, it will then
313+
* search the global Animation Manager and look for it there.
314+
*
274315
* @method Phaser.GameObjects.Components.Animation#playAfterRepeat
275316
* @fires Phaser.Animations.Events#ANIMATION_START
276317
* @fires Phaser.Animations.Events#SPRITE_ANIMATION_START
@@ -295,12 +336,18 @@ var Sprite = new Class({
295336
*
296337
* An animation set to repeat forever will never enter a completed state.
297338
*
298-
* You can chain a new animation at any point, including before the current one starts playing, during it, or when it ends (via its `animationcomplete` event).
339+
* You can chain a new animation at any point, including before the current one starts playing, during it,
340+
* or when it ends (via its `animationcomplete` event).
299341
*
300-
* Chained animations are specific to a Game Object, meaning different Game Objects can have different chained animations without impacting the global animation they're playing.
342+
* Chained animations are specific to a Game Object, meaning different Game Objects can have different chained
343+
* animations without impacting the animation they're playing.
301344
*
302345
* Call this method with no arguments to reset all currently chained animations.
303346
*
347+
* When playing an animation on a Sprite it will first check to see if it can find a matching key
348+
* locally within the Sprite. If it can, it will play the local animation. If not, it will then
349+
* search the global Animation Manager and look for it there.
350+
*
304351
* @method Phaser.GameObjects.Sprite#chain
305352
* @since 3.50.0
306353
*
@@ -359,7 +406,7 @@ var Sprite = new Class({
359406
},
360407

361408
/**
362-
* Stops the current animation from playing when it next repeats.
409+
* Stops the current animation from playing after the given number of repeats.
363410
*
364411
* It then dispatches the `ANIMATION_STOP` series of events.
365412
*

0 commit comments

Comments
 (0)