Phaser API Documentation

  Version: 
Filter
This is a beta release of our new docs system. Found an issue?
Please tell us about it in the #📖-newdocs-feedback channel on the Phaser Discord
Namespace: Events
Phaser.Animations.Events

Events

ADD_ANIMATION
Focus
Focus

Description:

The Add Animation Event.

This event is dispatched when a new animation is added to the global Animation Manager.

This can happen either as a result of an animation instance being added to the Animation Manager, or the Animation Manager creating a new animation directly.

Parameters:

name type description
key string

The key of the Animation that was added to the global Animation Manager.

animation Phaser.Animations.Animation

An instance of the newly created Animation.

Since: 3.0.0
Focus
Focus
ANIMATION_COMPLETE
Focus
Focus

Description:

The Animation Complete Event.

This event is dispatched by a Sprite when an animation playing on it completes playback. This happens when the animation gets to the end of its sequence, factoring in any delays or repeats it may have to process.

An animation that is set to loop, or repeat forever, will never fire this event, because it never actually completes. If you need to handle this, listen for the ANIMATION_STOP event instead, as this is emitted when the animation is stopped directly.

Listen for it on the Sprite using sprite.on('animationcomplete', listener)

The animation event flow is as follows:

  1. ANIMATION_START
  2. ANIMATION_UPDATE (repeated for however many frames the animation has)
  3. ANIMATION_REPEAT (only if the animation is set to repeat, it then emits more update events after this)
  4. ANIMATION_COMPLETE (only if there is a finite, or zero, repeat count)
  5. ANIMATION_COMPLETE_KEY (only if there is a finite, or zero, repeat count)

If the animation is stopped directly, the ANIMATION_STOP event is dispatched instead of ANIMATION_COMPLETE.

If the animation is restarted while it is already playing, ANIMATION_RESTART is emitted.

Parameters:

name type description
animation Phaser.Animations.Animation

A reference to the Animation that completed.

frame Phaser.Animations.AnimationFrame

The current Animation Frame of the Animation.

gameObject Phaser.GameObjects.Sprite

A reference to the Game Object on which the animation updated.

frameKey string

The unique key of the Animation Frame within the Animation.

Focus
Focus
ANIMATION_COMPLETE_KEY
Focus
Focus

Description:

The Animation Complete Dynamic Key Event.

This event is dispatched by a Sprite when an animation playing on it completes playback. This happens when the animation gets to the end of its sequence, factoring in any delays or repeats it may have to process.

An animation that is set to loop, or repeat forever, will never fire this event, because it never actually completes. If you need to handle this, listen for the ANIMATION_STOP event instead, as this is emitted when the animation is stopped directly.

The difference between this and the ANIMATION_COMPLETE event is that this one has a dynamic event name that contains the name of the animation within it. For example, if you had an animation called explode you could listen for the completion of that specific animation by using: sprite.on('animationcomplete-explode', listener). Or, if you wish to use types: sprite.on(Phaser.Animations.Events.ANIMATION_COMPLETE_KEY + 'explode', listener).

The animation event flow is as follows:

  1. ANIMATION_START
  2. ANIMATION_UPDATE (repeated for however many frames the animation has)
  3. ANIMATION_REPEAT (only if the animation is set to repeat, it then emits more update events after this)
  4. ANIMATION_COMPLETE (only if there is a finite, or zero, repeat count)
  5. ANIMATION_COMPLETE_KEY (only if there is a finite, or zero, repeat count)

If the animation is stopped directly, the ANIMATION_STOP event is dispatched instead of ANIMATION_COMPLETE.

If the animation is restarted while it is already playing, ANIMATION_RESTART is emitted.

Parameters:

name type description
animation Phaser.Animations.Animation

A reference to the Animation that completed.

frame Phaser.Animations.AnimationFrame

The current Animation Frame of the Animation.

gameObject Phaser.GameObjects.Sprite

A reference to the Game Object on which the animation updated.

frameKey string

The unique key of the Animation Frame within the Animation.

Focus
Focus
ANIMATION_REPEAT
Focus
Focus

Description:

The Animation Repeat Event.

This event is dispatched by a Sprite when an animation repeats playing on it. This happens if the animation was created, or played, with a repeat value specified.

An animation will repeat when it reaches the end of its sequence.

Listen for it on the Sprite using sprite.on('animationrepeat', listener)

The animation event flow is as follows:

  1. ANIMATION_START
  2. ANIMATION_UPDATE (repeated for however many frames the animation has)
  3. ANIMATION_REPEAT (only if the animation is set to repeat, it then emits more update events after this)
  4. ANIMATION_COMPLETE (only if there is a finite, or zero, repeat count)
  5. ANIMATION_COMPLETE_KEY (only if there is a finite, or zero, repeat count)

If the animation is stopped directly, the ANIMATION_STOP event is dispatched instead of ANIMATION_COMPLETE.

If the animation is restarted while it is already playing, ANIMATION_RESTART is emitted.

Parameters:

name type description
animation Phaser.Animations.Animation

A reference to the Animation that has repeated.

frame Phaser.Animations.AnimationFrame

The current Animation Frame of the Animation.

gameObject Phaser.GameObjects.Sprite

A reference to the Game Object on which the animation repeated.

frameKey string

The unique key of the Animation Frame within the Animation.

Since: 3.50.0
Focus
Focus
ANIMATION_RESTART
Focus
Focus

Description:

The Animation Restart Event.

This event is dispatched by a Sprite when an animation restarts playing on it. This only happens when the Sprite.anims.restart method is called.

Listen for it on the Sprite using sprite.on('animationrestart', listener)

The animation event flow is as follows:

  1. ANIMATION_START
  2. ANIMATION_UPDATE (repeated for however many frames the animation has)
  3. ANIMATION_REPEAT (only if the animation is set to repeat, it then emits more update events after this)
  4. ANIMATION_COMPLETE (only if there is a finite, or zero, repeat count)
  5. ANIMATION_COMPLETE_KEY (only if there is a finite, or zero, repeat count)

If the animation is stopped directly, the ANIMATION_STOP event is dispatched instead of ANIMATION_COMPLETE.

If the animation is restarted while it is already playing, ANIMATION_RESTART is emitted.

Parameters:

name type description
animation Phaser.Animations.Animation

A reference to the Animation that has restarted.

frame Phaser.Animations.AnimationFrame

The current Animation Frame of the Animation.

gameObject Phaser.GameObjects.Sprite

A reference to the Game Object on which the animation restarted.

frameKey string

The unique key of the Animation Frame within the Animation.

Focus
Focus
ANIMATION_START
Focus
Focus

Description:

The Animation Start Event.

This event is dispatched by a Sprite when an animation starts playing on it. This happens when the animation is played, factoring in any delay that may have been specified. This event happens after the delay has expired and prior to the first update event.

Listen for it on the Sprite using sprite.on('animationstart', listener)

The animation event flow is as follows:

  1. ANIMATION_START
  2. ANIMATION_UPDATE (repeated for however many frames the animation has)
  3. ANIMATION_REPEAT (only if the animation is set to repeat, it then emits more update events after this)
  4. ANIMATION_COMPLETE (only if there is a finite, or zero, repeat count)
  5. ANIMATION_COMPLETE_KEY (only if there is a finite, or zero, repeat count)

If the animation is stopped directly, the ANIMATION_STOP event is dispatched instead of ANIMATION_COMPLETE.

If the animation is restarted while it is already playing, ANIMATION_RESTART is emitted.

Parameters:

name type description
animation Phaser.Animations.Animation

A reference to the Animation that has started.

frame Phaser.Animations.AnimationFrame

The current Animation Frame of the Animation.

gameObject Phaser.GameObjects.Sprite

A reference to the Game Object on which the animation started.

frameKey string

The unique key of the Animation Frame within the Animation.

Since: 3.50.0
Focus
Focus
ANIMATION_STOP
Focus
Focus

Description:

The Animation Stop Event.

This event is dispatched by a Sprite when an animation is stopped on it. An animation will only be stopeed if a method such as Sprite.stop or Sprite.anims.stopAfterDelay is called. It can also be emitted if a new animation is started before the current one completes.

Listen for it on the Sprite using sprite.on('animationstop', listener)

The animation event flow is as follows:

  1. ANIMATION_START
  2. ANIMATION_UPDATE (repeated for however many frames the animation has)
  3. ANIMATION_REPEAT (only if the animation is set to repeat, it then emits more update events after this)
  4. ANIMATION_COMPLETE (only if there is a finite, or zero, repeat count)
  5. ANIMATION_COMPLETE_KEY (only if there is a finite, or zero, repeat count)

If the animation is stopped directly, the ANIMATION_STOP event is dispatched instead of ANIMATION_COMPLETE.

If the animation is restarted while it is already playing, ANIMATION_RESTART is emitted.

Parameters:

name type description
animation Phaser.Animations.Animation

A reference to the Animation that has stopped.

frame Phaser.Animations.AnimationFrame

The current Animation Frame of the Animation.

gameObject Phaser.GameObjects.Sprite

A reference to the Game Object on which the animation stopped.

frameKey string

The unique key of the Animation Frame within the Animation.

Since: 3.50.0
Focus
Focus
ANIMATION_UPDATE
Focus
Focus

Description:

The Animation Update Event.

This event is dispatched by a Sprite when an animation playing on it updates. This happens when the animation changes frame. An animation will change frame based on the frme rate and other factors like timeScale and delay. It can also change frame when stopped or restarted.

Listen for it on the Sprite using sprite.on('animationupdate', listener)

If an animation is playing faster than the game frame-rate can handle, it's entirely possible for it to emit several update events in a single game frame, so please be aware of this in your code. The final event received that frame is the one that is rendered to the game.

The animation event flow is as follows:

  1. ANIMATION_START
  2. ANIMATION_UPDATE (repeated for however many frames the animation has)
  3. ANIMATION_REPEAT (only if the animation is set to repeat, it then emits more update events after this)
  4. ANIMATION_COMPLETE (only if there is a finite, or zero, repeat count)
  5. ANIMATION_COMPLETE_KEY (only if there is a finite, or zero, repeat count)

If the animation is stopped directly, the ANIMATION_STOP event is dispatched instead of ANIMATION_COMPLETE.

If the animation is restarted while it is already playing, ANIMATION_RESTART is emitted.

Parameters:

name type description
animation Phaser.Animations.Animation

A reference to the Animation that has updated.

frame Phaser.Animations.AnimationFrame

The current Animation Frame of the Animation.

gameObject Phaser.GameObjects.Sprite

A reference to the Game Object on which the animation updated.

frameKey string

The unique key of the Animation Frame within the Animation.

Since: 3.50.0
Focus
Focus
PAUSE_ALL
Focus
Focus

Description:

The Pause All Animations Event.

This event is dispatched when the global Animation Manager is told to pause.

When this happens all current animations will stop updating, although it doesn't necessarily mean that the game has paused as well.

Since: 3.0.0
Focus
Focus
REMOVE_ANIMATION
Focus
Focus

Description:

The Remove Animation Event.

This event is dispatched when an animation is removed from the global Animation Manager.

Parameters:

name type description
key string

The key of the Animation that was removed from the global Animation Manager.

animation Phaser.Animations.Animation

An instance of the removed Animation.

Focus
Focus
RESUME_ALL
Focus
Focus

Description:

The Resume All Animations Event.

This event is dispatched when the global Animation Manager resumes, having been previously paused.

When this happens all current animations will continue updating again.

Since: 3.0.0
Focus
Focus