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 16)

Extends

Members


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

The Animations registered in the Animation Manager.

This map should be modified with the #add and #create methods of the Animation Manager.

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

<protected> game :Phaser.Game

A reference to the Phaser.Game instance.

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

globalTimeScale :number

The global time scale of the Animation Manager.

This scales the time delta between two frames, thus influencing the speed of time for the Animation Manager.

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

name :string

The name of this Animation Manager.

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

paused :boolean

Whether the Animation Manager is paused along with all of its Animations.

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

<protected> textureManager :Phaser.Textures.TextureManager

A reference to the Texture Manager.

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

Methods


add(key, animation)

Adds an existing Animation to the Animation Manager.

Parameters:
Name Type Description
key string

The key under which the Animation should be added. The Animation will be updated with it. Must be unique.

animation Phaser.Animations.Animation

The Animation which should be added to the Animation Manager.

Since: 3.0.0
Source: src/animations/AnimationManager.js (Line 124)
Fires:
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()

Registers event listeners after the Game boots.

Since: 3.0.0
Source: src/animations/AnimationManager.js (Line 110)
Listens to Events:

create(config)

Creates a new Animation and adds it to the Animation Manager.

Animations are global. Once created, you can use them in any Scene in your game. They are not Scene specific.

If an invalid key is given this method will return false.

If you pass the key of an animation that already exists in the Animation Manager, that animation will be returned.

A brand new animation is only created if the key is valid and not already in use.

If you wish to re-use an existing key, call AnimationManager.remove first, then this method.

Parameters:
Name Type Description
config Phaser.Animations.Types.Animation

The configuration settings for the Animation.

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

The Animation that was created, or false is the key is already in use.

Type
Phaser.Animations.Animation | false

destroy()

Destroy this Animation Manager and clean up animation definitions and references to other objects. This method should not be called directly. It will be called automatically as a response to a destroy event from the Phaser.Game instance.

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

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

exists(key)

Checks to see if the given key is already in use within the Animation Manager or not.

Animations are global. Keys created in one scene can be used from any other Scene in your game. They are not Scene specific.

Parameters:
Name Type Description
key string

The key of the Animation to check.

Since: 3.16.0
Source: src/animations/AnimationManager.js (Line 154)
Returns:

true if the Animation already exists in the Animation Manager, or false if the key is available.

Type
boolean

fromJSON(data [, clearCurrentAnimations])

Loads this Animation Manager's Animations and settings from a JSON object.

Parameters:
Name Type Argument Default Description
data string | Phaser.Animations.Types.JSONAnimations | Phaser.Animations.Types.JSONAnimation

The JSON object to parse.

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 215)
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])

[description]

Parameters:
Name Type Argument Description
key string

The key for the texture containing the animation frames.

config Phaser.Animations.Types.GenerateFrameNames <optional>

The configuration object for the animation frame names.

Since: 3.0.0
Source: src/animations/AnimationManager.js (Line 264)
Returns:
Type
Array.<Phaser.Animations.Types.AnimationFrame>

generateFrameNumbers(key, config)

Generate an array of Phaser.Animations.Types.AnimationFrame objects from a texture key and configuration object.

Generates objects with numbered frame names, as configured by the given Phaser.Animations.Types.GenerateFrameNumbers.

Parameters:
Name Type Description
key string

The key for the texture containing the animation frames.

config Phaser.Animations.Types.GenerateFrameNumbers

The configuration object for the animation frames.

Since: 3.0.0
Source: src/animations/AnimationManager.js (Line 339)
Returns:
Type
Array.<Phaser.Animations.Types.AnimationFrame>

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 405)
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 420)
Returns:

The Game Object with the animation loaded into it.

Type
Phaser.GameObjects.GameObject

off(event [, fn] [, context] [, once])

Remove the listeners of a given event.

Parameters:
Name Type Argument Description
event string | symbol

The event name.

fn function <optional>

Only remove the listeners that match this function.

context * <optional>

Only remove the listeners that have this context.

once boolean <optional>

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 444)
Fires:
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 465)
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 498)
Fires:
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 Argument Description
event string | symbol

The event name.

fn function <optional>

Only remove the listeners that match this function.

context * <optional>

Only remove the listeners that have this context.

once boolean <optional>

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 523)
Fires:
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 544)
Returns:

This Animation Manager.

Type
Phaser.Animations.AnimationManager

toJSON(key)

Get the animation data as javascript object by giving key, or get the data of all animations as array of objects, if key wasn't provided.

Parameters:
Name Type Description
key string

[description]

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

[description]

Type
Phaser.Animations.Types.JSONAnimations