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:
- animation/AnimationManager.js, line 16
Members
-
currentFrame
-
- Default Value:
- null
- Source:
- animation/AnimationManager.js, line 32
Properties:
Name Type Description currentFrame
Phaser.Animation.Frame The currently displayed Frame of animation, if any. -
game
-
- Source:
- animation/AnimationManager.js, line 26
Properties:
Name Type Description game
Phaser.Game A reference to the currently running Game. -
sprite
-
- Source:
- animation/AnimationManager.js, line 21
Properties:
Name Type Description sprite
Phaser.Sprite A reference to the parent Sprite that owns this AnimationManager. -
updateIfVisible
-
- Default Value:
- true
- Source:
- animation/AnimationManager.js, line 38
Properties:
Name Type Description updateIfVisible
boolean Should the animation data continue to update even if the Sprite.visible is set to false.
Methods
-
<static> add(name, frames, frameRate, loop, useNumericIndex) → {Phaser.Animation}
-
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 {boolean} - 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:
- animation/AnimationManager.js, line 79
Returns:
The Animation object that was created.- Type
- Phaser.Animation
-
<static> destroy()
-
Destroys all references this AnimationManager contains. Sets the _anims to a new object and nulls the current animation.
- Source:
- animation/AnimationManager.js, line 249
-
<static> play(name, frameRate, loop) → {Phaser.Animation}
-
Play an animation based on the given key. The animation should previously have been added via sprite.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.
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>
null Should the animation be looped after playback. If not provided the previously set loop value of the Animation is used. - Source:
- animation/AnimationManager.js, line 161
Returns:
A reference to playing Animation instance.- Type
- Phaser.Animation
-
<static> 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:
- animation/AnimationManager.js, line 192
-
<protected, static> update() → {boolean}
-
The main update function is called by the Sprites update loop. It's responsible for updating animation frames and firing related events.
- Source:
- animation/AnimationManager.js, line 223
Returns:
True if a new animation frame has been set, otherwise false.- Type
- boolean
-
<static> validateFrames(frames, useNumericIndex) → {boolean}
-
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:
- animation/AnimationManager.js, line 126
Returns:
True if all given Frames are valid, otherwise false.- Type
- boolean