Class: AnimationManager

Phaser.Animations. AnimationManager

The Animation Manager.

Animations are managed by the global Animation Manager. This is a singleton class that is
responsible for creating and delivering animations and their corresponding data to all Game Objects.
Unlike plugins it is owned by the Game instance, not the Scene.

Sprites and other Game Objects get the data they need from the AnimationManager.


new AnimationManager(game)

Parameters:
Name Type Description
game Phaser.Game

A reference to the Phaser.Game instance.

Since: 3.0.0
Source: src/animations/AnimationManager.js (Line 21)

Extends

Members


<protected> anims :Phaser.Structs.Map.<string, Phaser.Animations.Animation>

[description]

Type:
Since: 3.0.0
Source: src/animations/AnimationManager.js (Line 79)

<protected> game :Phaser.Game

A reference to the Phaser.Game instance.

Type:
Since: 3.0.0
Source: src/animations/AnimationManager.js (Line 49)

globalTimeScale :number

[description]

Type:
  • number
Since: 3.0.0
Default Value:
  • 1
Source: src/animations/AnimationManager.js (Line 69)

name :string

[description]

Type:
  • string
Since: 3.0.0
Source: src/animations/AnimationManager.js (Line 99)

paused :boolean

[description]

Type:
  • boolean
Since: 3.0.0
Default Value:
  • false
Source: src/animations/AnimationManager.js (Line 89)

<protected> textureManager :Phaser.Textures.TextureManager

A reference to the Texture Manager.

Type:
Since: 3.0.0
Source: src/animations/AnimationManager.js (Line 59)

Methods


add(key, animation)

[description]

Parameters:
Name Type Description
key string

[description]

animation Phaser.Animations.Animation

[description]

Since: 3.0.0
Source: src/animations/AnimationManager.js (Line 124)
Fires:
  • event:AddAnimationEvent
Returns:

This Animation Manager.

Type
Phaser.Animations.AnimationManager

addListener(event, fn [, context])

Add a listener for a given event.

Parameters:
Name Type Argument Default Description
event string | symbol

The event name.

fn function

The listener function.

context * <optional>
this

The context to invoke the listener with.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 111)
Returns:

this.

Type
Phaser.Events.EventEmitter

boot()

[description]

Since: 3.0.0
Source: src/animations/AnimationManager.js (Line 111)

create(config)

[description]

Parameters:
Name Type Description
config AnimationConfig

[description]

Since: 3.0.0
Source: src/animations/AnimationManager.js (Line 153)
Fires:
  • event:AddAnimationEvent
Returns:

The Animation that was created.

Type
Phaser.Animations.Animation

destroy()

[description]

Since: 3.0.0
Overrides:
Source: src/animations/AnimationManager.js (Line 608)

emit(event [, args])

Calls each of the listeners registered for a given event.

Parameters:
Name Type Argument Description
event string | symbol

The event name.

args * <optional>
<repeatable>

Additional arguments that will be passed to the event handler.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 86)
Returns:

true if the event had listeners, else false.

Type
boolean

eventNames()

Return an array listing the events for which the emitter has registered listeners.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 55)
Returns:
Type
array

fromJSON(data [, clearCurrentAnimations])

[description]

Parameters:
Name Type Argument Default Description
data string | JSONAnimationManager | JSONAnimation

[description]

clearCurrentAnimations boolean <optional>
false

If set to true, the current animations will be removed (anims.clear()). If set to false (default), the animations in data will be added.

Since: 3.0.0
Source: src/animations/AnimationManager.js (Line 183)
Returns:

An array containing all of the Animation objects that were created as a result of this call.

Type
Array.<Phaser.Animations.Animation>

generateFrameNames(key [, config])

Generate an array of AnimationFrameConfig objects from a texture key and configuration object.

Generates objects with string frame names, as configured by the given AnimationFrameConfig.

Parameters:
Name Type Argument Description
key string

The key for the texture containing the animation frames.

config GenerateFrameNamesConfig <optional>

The configuration object for the animation frame names.

Since: 3.0.0
Source: src/animations/AnimationManager.js (Line 244)
Returns:

The array of AnimationFrameConfig objects.

Type
Array.<AnimationFrameConfig>

generateFrameNumbers(key, config)

Generate an array of AnimationFrameConfig objects from a texture key and configuration object.

Generates objects with numbered frame names, as configured by the given GenerateFrameNumbersConfig.

Parameters:
Name Type Description
key string

The key for the texture containing the animation frames.

config GenerateFrameNumbersConfig

The configuration object for the animation frames.

Since: 3.0.0
Source: src/animations/AnimationManager.js (Line 331)
Returns:

The array of AnimationFrameConfig objects.

Type
Array.<AnimationFrameConfig>

get(key)

Get an Animation.

Parameters:
Name Type Description
key string

The key of the Animation to retrieve.

Since: 3.0.0
Source: src/animations/AnimationManager.js (Line 397)
Returns:

The Animation.

Type
Phaser.Animations.Animation

listenerCount(event)

Return the number of listeners listening to a given event.

Parameters:
Name Type Description
event string | symbol

The event name.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 75)
Returns:

The number of listeners.

Type
number

listeners(event)

Return the listeners registered for a given event.

Parameters:
Name Type Description
event string | symbol

The event name.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 64)
Returns:

The registered listeners.

Type
array

load(child, key [, startFrame])

Load an Animation into a Game Object's Animation Component.

Parameters:
Name Type Argument Description
child Phaser.GameObjects.GameObject

The Game Object to load the animation into.

key string

The key of the animation to load.

startFrame string | integer <optional>

The name of a start frame to set on the loaded animation.

Since: 3.0.0
Source: src/animations/AnimationManager.js (Line 412)
Returns:

[description]

Type
Phaser.GameObjects.GameObject

off(event, fn, context, once)

Remove the listeners of a given event.

Parameters:
Name Type Description
event string | symbol

The event name.

fn function

Only remove the listeners that match this function.

context *

Only remove the listeners that have this context.

once boolean

Only remove one-time listeners.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 151)
Returns:

this.

Type
Phaser.Events.EventEmitter

on(event, fn [, context])

Add a listener for a given event.

Parameters:
Name Type Argument Default Description
event string | symbol

The event name.

fn function

The listener function.

context * <optional>
this

The context to invoke the listener with.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 98)
Returns:

this.

Type
Phaser.Events.EventEmitter

once(event, fn [, context])

Add a one-time listener for a given event.

Parameters:
Name Type Argument Default Description
event string | symbol

The event name.

fn function

The listener function.

context * <optional>
this

The context to invoke the listener with.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 124)
Returns:

this.

Type
Phaser.Events.EventEmitter

pauseAll()

Pause all animations.

Since: 3.0.0
Source: src/animations/AnimationManager.js (Line 436)
Fires:
  • event:PauseAllAnimationEvent
Returns:

This Animation Manager.

Type
Phaser.Animations.AnimationManager

play(key, child)

Play an animation on the given Game Objects that have an Animation Component.

Parameters:
Name Type Description
key string

The key of the animation to play on the Game Object.

child Phaser.GameObjects.GameObject | Array.<Phaser.GameObjects.GameObject>

The Game Objects to play the animation on.

Since: 3.0.0
Source: src/animations/AnimationManager.js (Line 457)
Returns:

This Animation Manager.

Type
Phaser.Animations.AnimationManager

remove(key)

Remove an animation.

Parameters:
Name Type Description
key string

The key of the animation to remove.

Since: 3.0.0
Source: src/animations/AnimationManager.js (Line 490)
Fires:
  • event:RemoveAnimationEvent
Returns:

[description]

Type
Phaser.Animations.Animation

removeAllListeners( [event])

Remove all listeners, or those of the specified event.

Parameters:
Name Type Argument Description
event string | symbol <optional>

The event name.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 165)
Returns:

this.

Type
Phaser.Events.EventEmitter

removeListener(event, fn, context, once)

Remove the listeners of a given event.

Parameters:
Name Type Description
event string | symbol

The event name.

fn function

Only remove the listeners that match this function.

context *

Only remove the listeners that have this context.

once boolean

Only remove one-time listeners.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 137)
Returns:

this.

Type
Phaser.Events.EventEmitter

resumeAll()

Resume all paused animations.

Since: 3.0.0
Source: src/animations/AnimationManager.js (Line 515)
Fires:
  • event:ResumeAllAnimationEvent
Returns:

This Animation Manager.

Type
Phaser.Animations.AnimationManager

shutdown()

Removes all listeners.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 31)

staggerPlay(key, children [, stagger])

Takes an array of Game Objects that have an Animation Component and then
starts the given animation playing on them, each one offset by the
stagger amount given to this method.

Parameters:
Name Type Argument Default Description
key string

The key of the animation to play on the Game Objects.

children Phaser.GameObjects.GameObject | Array.<Phaser.GameObjects.GameObject>

An array of Game Objects to play the animation on. They must have an Animation Component.

stagger number <optional>
0

The amount of time, in milliseconds, to offset each play time by.

Since: 3.0.0
Source: src/animations/AnimationManager.js (Line 536)
Returns:

This Animation Manager.

Type
Phaser.Animations.AnimationManager

toJSON(key)

[description]

Parameters:
Name Type Description
key string

[description]

Since: 3.0.0
Source: src/animations/AnimationManager.js (Line 576)
Returns:

[description]

Type
JSONAnimationManager