Skip to content

Commit afef6da

Browse files
committed
Exposed all of the new animation methods on a Sprite level
1 parent 1d79844 commit afef6da

1 file changed

Lines changed: 141 additions & 13 deletions

File tree

src/gameobjects/sprite/Sprite.js

Lines changed: 141 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,12 @@ var Sprite = new Class({
176176
*
177177
* @param {(string|Phaser.Animations.Animation|Phaser.Types.Animations.PlayAnimationConfig)} key - The string-based key of the animation to play, or an Animation instance, or a `PlayAnimationConfig` object.
178178
* @param {boolean} [ignoreIfPlaying=false] - If an animation is already playing then ignore this call.
179-
* @param {integer} [startFrame=0] - Optionally start the animation playing from this frame index.
180179
*
181180
* @return {this} This Game Object.
182181
*/
183-
play: function (key, ignoreIfPlaying, startFrame)
182+
play: function (key, ignoreIfPlaying)
184183
{
185-
return this.anims.play(key, ignoreIfPlaying, startFrame);
184+
return this.anims.play(key, ignoreIfPlaying);
186185
},
187186

188187
/**
@@ -228,37 +227,90 @@ var Sprite = new Class({
228227
*
229228
* @param {(string|Phaser.Animations.Animation|Phaser.Types.Animations.PlayAnimationConfig)} key - The string-based key of the animation to play, or an Animation instance, or a `PlayAnimationConfig` object.
230229
* @param {boolean} [ignoreIfPlaying=false] - If an animation is already playing then ignore this call.
231-
* @param {integer} [startFrame=0] - Optionally start the animation playing from this frame index.
232230
*
233231
* @return {this} This Game Object.
234232
*/
235-
playReverse: function (key, ignoreIfPlaying, startFrame)
233+
playReverse: function (key, ignoreIfPlaying)
236234
{
237-
return this.anims.playReverse(key, ignoreIfPlaying, startFrame);
235+
return this.anims.playReverse(key, ignoreIfPlaying);
238236
},
239237

240238
/**
241-
* Waits for the specified delay, in milliseconds, then starts playback of the requested animation.
239+
* Waits for the specified delay, in milliseconds, then starts playback of the given animation.
242240
*
243-
* If the animation _also_ has a delay value set in its config, this value will override that and be used instead.
241+
* If the animation _also_ has a delay value set in its config, it will be **added** to the delay given here.
244242
*
245-
* The delay only takes effect if the animation has not already started playing.
243+
* If an animation is already running and a new animation is given to this method, it will wait for
244+
* the given delay before starting the new animation.
246245
*
247-
* @method Phaser.GameObjects.Sprite#delayedPlay
246+
* If no animation is currently running, the given one begins after the delay.
247+
*
248+
* Prior to Phaser 3.50 this method was called 'delayedPlay'.
249+
*
250+
* @method Phaser.GameObjects.Components.Animation#playAfterDelay
248251
* @fires Phaser.Animations.Events#ANIMATION_START
249252
* @fires Phaser.Animations.Events#SPRITE_ANIMATION_START
250253
* @fires Phaser.Animations.Events#SPRITE_ANIMATION_KEY_START
251254
* @since 3.50.0
252255
*
256+
* @param {(string|Phaser.Animations.Animation|Phaser.Types.Animations.PlayAnimationConfig)} key - The string-based key of the animation to play, or an Animation instance, or a `PlayAnimationConfig` object.
253257
* @param {integer} delay - The delay, in milliseconds, to wait before starting the animation playing.
258+
*
259+
* @return {this} This Game Object.
260+
*/
261+
playAfterDelay: function (key, delay)
262+
{
263+
return this.anims.playAfterDelay(key, delay);
264+
},
265+
266+
/**
267+
* Waits for the current animation to complete one 'repeat' cycle, then starts playback of the given animation.
268+
*
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.
271+
*
272+
* If no animation is currently running, the given one will start immediately.
273+
*
274+
* @method Phaser.GameObjects.Components.Animation#playAfterRepeat
275+
* @fires Phaser.Animations.Events#ANIMATION_START
276+
* @fires Phaser.Animations.Events#SPRITE_ANIMATION_START
277+
* @fires Phaser.Animations.Events#SPRITE_ANIMATION_KEY_START
278+
* @since 3.50.0
279+
*
254280
* @param {(string|Phaser.Animations.Animation|Phaser.Types.Animations.PlayAnimationConfig)} key - The string-based key of the animation to play, or an Animation instance, or a `PlayAnimationConfig` object.
255-
* @param {integer} [startFrame=0] - The frame of the animation to start from.
281+
* @param {integer} [repeatCount=1] - How many times should the animation repeat before the next one starts?
256282
*
257283
* @return {this} This Game Object.
258284
*/
259-
delayedPlay: function (delay, key, startFrame)
285+
playAfterRepeat: function (key, repeatCount)
260286
{
261-
return this.anims.delayedPlay(delay, key, startFrame);
287+
return this.anims.playAfterRepeat(key, repeatCount);
288+
},
289+
290+
/**
291+
* Sets an animation, or an array of animations, to be played immediately after the current one completes or stops.
292+
*
293+
* The current animation must enter a 'completed' state for this to happen, i.e. finish all of its repeats, delays, etc,
294+
* or have the `stop` method called directly on it.
295+
*
296+
* An animation set to repeat forever will never enter a completed state.
297+
*
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).
299+
*
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.
301+
*
302+
* Call this method with no arguments to reset all currently chained animations.
303+
*
304+
* @method Phaser.GameObjects.Sprite#chain
305+
* @since 3.50.0
306+
*
307+
* @param {(string|Phaser.Animations.Animation|Phaser.Types.Animations.PlayAnimationConfig|string[]|Phaser.Animations.Animation[]|Phaser.Types.Animations.PlayAnimationConfig[])} key - The string-based key of the animation to play, or an Animation instance, or a `PlayAnimationConfig` object, or an array of them.
308+
*
309+
* @return {this} This Game Object.
310+
*/
311+
chain: function (key)
312+
{
313+
return this.anims.chain(key);
262314
},
263315

264316
/**
@@ -281,6 +333,82 @@ var Sprite = new Class({
281333
return this.anims.stop();
282334
},
283335

336+
/**
337+
* Stops the current animation from playing after the specified time delay, given in milliseconds.
338+
*
339+
* It then dispatches the `ANIMATION_STOP` series of events.
340+
*
341+
* If no animation is running, no events will be dispatched.
342+
*
343+
* If there is another animation in the queue (set via the `chain` method) then it will start playing,
344+
* when the current one stops.
345+
*
346+
* @method Phaser.GameObjects.Sprite#stopAfterDelay
347+
* @fires Phaser.Animations.Events#ANIMATION_STOP
348+
* @fires Phaser.Animations.Events#SPRITE_ANIMATION_STOP
349+
* @fires Phaser.Animations.Events#SPRITE_ANIMATION_KEY_STOP
350+
* @since 3.50.0
351+
*
352+
* @param {integer} delay - The number of milliseconds to wait before stopping this animation.
353+
*
354+
* @return {this} This Game Object.
355+
*/
356+
stopAfterDelay: function (delay)
357+
{
358+
return this.anims.stopAfterDelay(delay);
359+
},
360+
361+
/**
362+
* Stops the current animation from playing when it next repeats.
363+
*
364+
* It then dispatches the `ANIMATION_STOP` series of events.
365+
*
366+
* If no animation is running, no events will be dispatched.
367+
*
368+
* If there is another animation in the queue (set via the `chain` method) then it will start playing,
369+
* when the current one stops.
370+
*
371+
* @method Phaser.GameObjects.Sprite#stopAfterRepeat
372+
* @fires Phaser.Animations.Events#ANIMATION_STOP
373+
* @fires Phaser.Animations.Events#SPRITE_ANIMATION_STOP
374+
* @fires Phaser.Animations.Events#SPRITE_ANIMATION_KEY_STOP
375+
* @since 3.50.0
376+
*
377+
* @param {integer} [repeatCount=1] - How many times should the animation repeat before stopping?
378+
*
379+
* @return {this} This Game Object.
380+
*/
381+
stopAfterRepeat: function (repeatCount)
382+
{
383+
return this.anims.stopAfterRepeat(repeatCount);
384+
},
385+
386+
/**
387+
* Stops the current animation from playing when it next sets the given frame.
388+
* If this frame doesn't exist within the animation it will not stop it from playing.
389+
*
390+
* It then dispatches the `ANIMATION_STOP` series of events.
391+
*
392+
* If no animation is running, no events will be dispatched.
393+
*
394+
* If there is another animation in the queue (set via the `chain` method) then it will start playing,
395+
* when the current one stops.
396+
*
397+
* @method Phaser.GameObjects.Sprite#stopOnFrame
398+
* @fires Phaser.Animations.Events#ANIMATION_STOP
399+
* @fires Phaser.Animations.Events#SPRITE_ANIMATION_STOP
400+
* @fires Phaser.Animations.Events#SPRITE_ANIMATION_KEY_STOP
401+
* @since 3.50.0
402+
*
403+
* @param {Phaser.Animations.AnimationFrame} frame - The frame to check before stopping this animation.
404+
*
405+
* @return {this} This Game Object.
406+
*/
407+
stopOnFrame: function (frame)
408+
{
409+
return this.anims.stopOnFrame(frame);
410+
},
411+
284412
/**
285413
* Build a JSON representation of this Sprite.
286414
*

0 commit comments

Comments
 (0)