Class: AnimationManager

Phaser. AnimationManager

new AnimationManager(sprite)

The Animation Manager is used to add, play and update Phaser Animations. Any Game Object such as Phaser.Sprite that supports animation contains a single AnimationManager instance.

Parameters:
Name Type Description
sprite Phaser.Sprite

A reference to the Game Object that owns this AnimationManager.

Source:
src/animation/AnimationManager.js line 15

Members

currentAnim : Phaser.Animation

The currently displayed animation, if any.

Type:
Source:
src/animation/AnimationManager.js line 40

currentFrame : Phaser.Frame

The currently displayed Frame of animation, if any. This property is only set once an Animation starts playing. Until that point it remains set as null.

Type:
Source:
src/animation/AnimationManager.js line 34

frame : number

Gets or sets the current frame index and updates the Texture Cache for display.

Type:
  • number
Source:
src/animation/AnimationManager.js line 485

<readonly> frameData : Phaser.FrameData

The current animations FrameData.

Type:
Source:
src/animation/AnimationManager.js line 426

frameName : string

Gets or sets the current frame name and updates the Texture Cache for display.

Type:
  • string
Source:
src/animation/AnimationManager.js line 509

<readonly> frameTotal : number

The total number of frames in the currently loaded FrameData, or -1 if no FrameData is loaded.

Type:
  • number
Source:
src/animation/AnimationManager.js line 440

game : Phaser.Game

A reference to the currently running Game.

Type:
Source:
src/animation/AnimationManager.js line 25

isLoaded : boolean

Set to true once animation data has been loaded.

Type:
  • boolean
Source:
src/animation/AnimationManager.js line 52

name : string

Gets the current animation name, if set.

Type:
  • string
Source:
src/animation/AnimationManager.js line 472

paused : boolean

Gets and sets the paused state of the current animation.

Type:
  • boolean
Source:
src/animation/AnimationManager.js line 454

sprite : Phaser.Sprite

A reference to the parent Sprite that owns this AnimationManager.

Type:
Source:
src/animation/AnimationManager.js line 20

updateIfVisible : boolean

Update the animation data only while the the sprite is Phaser.Sprite#visible. Set to false to continue updating while the sprite is invisible.

Type:
  • boolean
Default Value:
  • true
Source:
src/animation/AnimationManager.js line 46

Methods

add(name [, frames] [, frameRate] [, loop] [, useNumericIndex])

Adds a new animation under the given key. Optionally set the frames, frame rate and loop. Animations added in this way are played back with the play function.

Parameters:
Name Type Argument Default Description
name string

The unique (within this Sprite) name for the animation, i.e. "run", "fire", "walk".

frames Array <optional>
null

An array of numbers/strings that correspond to the frames to add to this animation and in which order. e.g. [1, 2, 3] or ['run0', 'run1', run2]). If null then all frames will be used.

frameRate number <optional>
60

The speed at which the animation should play. The speed is given in frames per second.

loop boolean <optional>
false

Whether or not the animation is looped or just plays once.

useNumericIndex boolean <optional>
true

Are the given frames using numeric indexes (default) or strings?

Source:
src/animation/AnimationManager.js line 165
Returns:

The Animation object that was created.

Type
Phaser.Animation

destroy()

Destroys all references this AnimationManager contains. Iterates through the list of animations stored in this manager and calls destroy on each of them.

Source:
src/animation/AnimationManager.js line 395

getAnimation(name)

Returns an animation that was previously added by name.

Parameters:
Name Type Description
name string

The name of the animation to be returned, e.g. "fire".

Source:
src/animation/AnimationManager.js line 360
Returns:

The Animation instance, if found, otherwise null.

Type
Phaser.Animation

next( [quantity])

Advances by the given number of frames in the current animation, taking the loop value into consideration.

Parameters:
Name Type Argument Default Description
quantity number <optional>
1

The number of frames to advance.

Source:
src/animation/AnimationManager.js line 330

play(name [, frameRate] [, loop] [, killOnComplete])

Play an animation based on the given key. The animation should previously have been added via animations.add

If the requested animation is already playing this request will be ignored. If you need to reset an already running animation do so directly on the Animation object itself.

If you need to jump to a specific frame of this animation, then call play and immediately after it, set the frame you require (i.e. animation.play(); animation.frame = 4).

Parameters:
Name Type Argument Default Description
name string

The name of the animation to be played, e.g. "fire", "walk", "jump".

frameRate number <optional>
null

The framerate to play the animation at. The speed is given in frames per second. If not provided the previously set frameRate of the Animation is used.

loop boolean <optional>
false

Should the animation be looped after playback. If not provided the previously set loop value of the Animation is used.

killOnComplete boolean <optional>
false

If set to true when the animation completes (only happens if loop=false) the parent Sprite will be killed.

Source:
src/animation/AnimationManager.js line 244
Returns:

A reference to playing Animation instance.

Type
Phaser.Animation

previous( [quantity])

Moves backwards the given number of frames in the current animation, taking the loop value into consideration.

Parameters:
Name Type Argument Default Description
quantity number <optional>
1

The number of frames to move back.

Source:
src/animation/AnimationManager.js line 345

refreshFrame()

Refreshes the current frame data back to the parent Sprite and also resets the texture data.

Source:
src/animation/AnimationManager.js line 380

stop( [name] [, resetFrame])

Stop playback of an animation. If a name is given that specific animation is stopped, otherwise the current animation is stopped. The currentAnim property of the AnimationManager is automatically set to the animation given.

Parameters:
Name Type Argument Default Description
name string <optional>
null

The name of the animation to be stopped, e.g. "fire". If none is given the currently running animation is stopped.

resetFrame boolean <optional>
false

When the animation is stopped should the currentFrame be set to the first frame of the animation (true) or paused on the last frame displayed (false)

Source:
src/animation/AnimationManager.js line 289

<protected> update()

The main update function is called by the Sprites update loop. It's responsible for updating animation frames and firing related events.

Source:
src/animation/AnimationManager.js line 307
Returns:

True if a new animation frame has been set, otherwise false.

Type
boolean

validateFrames(frames [, useNumericIndex])

Check whether the frames in the given array are valid and exist.

Parameters:
Name Type Argument Default Description
frames Array

An array of frames to be validated.

useNumericIndex boolean <optional>
true

Validate the frames based on their numeric index (true) or string index (false)

Source:
src/animation/AnimationManager.js line 213
Returns:

True if all given Frames are valid, otherwise false.

Type
boolean

phaser-ce@2.20.1 is on GitHub and NPM

Documentation generated by JSDoc 3.6.11 on 2024-10-05 using Tomorrow.