new Animation(game, parent, name, frameData, frames, delay, looped)
An Animation instance contains a single animation and the controls to play it. It is created by the AnimationManager, consists of Animation.Frame objects and belongs to a single Game Object such as a Sprite.
Parameters:
Name | Type | Description |
---|---|---|
game |
Phaser.Game | A reference to the currently running game. |
parent |
Phaser.Sprite | A reference to the owner of this Animation. |
name |
string | The unique name for this animation, used in playback commands. |
frameData |
Phaser.Animation.FrameData | The FrameData object that contains all frames used by this Animation. |
frames |
Array.<number> | Array.<string> | An array of numbers or strings indicating which frames to play in which order. |
delay |
number | The time between each frame of the animation, given in ms. |
looped |
boolean | Should this animation loop or play through once. |
- Source:
Classes
Members
-
currentFrame
-
- Source:
Properties:
Name Type Description currentFrame
Phaser.Animation.Frame The currently displayed frame of the Animation.
-
delay
-
- Source:
Properties:
Name Type Description delay
number The delay in ms between each frame of the Animation.
-
frame
-
- Source:
Properties:
Name Type Description frame
number Gets or sets the current frame index and updates the Texture Cache for display.
-
frameTotal
-
- Source:
Properties:
Name Type Description frameTotal
number The total number of frames in the currently loaded FrameData, or -1 if no FrameData is loaded.
-
game
-
- Source:
Properties:
Name Type Description game
Phaser.Game A reference to the currently running Game.
-
isFinished
-
- Default Value:
- false
- Source:
Properties:
Name Type Description isFinished
boolean The finished state of the Animation. Set to true once playback completes, false during playback.
-
isPaused
-
- Default Value:
- false
- Source:
Properties:
Name Type Description isPaused
boolean The paused state of the Animation.
-
isPlaying
-
- Default Value:
- false
- Source:
Properties:
Name Type Description isPlaying
boolean The playing state of the Animation. Set to false once playback completes, true during playback.
-
looped
-
- Source:
Properties:
Name Type Description looped
boolean The loop state of the Animation.
-
name
-
- Source:
Properties:
Name Type Description name
string The user defined name given to this Animation.
-
paused
-
- Source:
Properties:
Name Type Description paused
boolean Gets and sets the paused state of this Animation.
Methods
-
<static> generateFrameNames(prefix, min, max, suffix, zeroPad)
-
Really handy function for when you are creating arrays of animation data but it's using frame names and not numbers. For example imagine you've got 30 frames named: 'explosion0001-large' to 'explosion_0030-large' You could use this function to generate those by doing: Phaser.Animation.generateFrameNames('explosion', 1, 30, '-large', 4);
Parameters:
Name Type Argument Default Description prefix
string The start of the filename. If the filename was 'explosion0001-large' the prefix would be 'explosion'.
min
number The number to start sequentially counting from. If your frames are named 'explosion_0001' to 'explosion_0034' the min is 1.
max
number The number to count up to. If your frames are named 'explosion_0001' to 'explosion_0034' the max is 34.
suffix
string <optional>
'' The end of the filename. If the filename was 'explosion_0001-large' the prefix would be '-large'.
zeroPad
number <optional>
0 The number of zeroes to pad the min and max values with. If your frames are named 'explosion_0001' to 'explosion_0034' then the zeroPad is 4.
- Source:
-
destroy()
-
Cleans up this animation ready for deletion. Nulls all values and references.
- Source:
-
onComplete()
-
Called internally when the animation finishes playback. Sets the isPlaying and isFinished states and dispatches the onAnimationComplete event if it exists on the parent.
- Source:
-
play(frameRate, loop) → {Phaser.Animation}
-
Plays this animation.
Parameters:
Name Type Argument Default Description 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:
Returns:
- A reference to this Animation instance.
- Type
- Phaser.Animation
-
restart()
-
Sets this animation back to the first frame and restarts the animation.
- Source:
-
stop(resetFrame)
-
Stops playback of this animation and set it to a finished state. If a resetFrame is provided it will stop playback and set frame to the first in the animation.
Parameters:
Name Type Argument Default Description resetFrame
boolean <optional>
false If true after the animation stops the currentFrame value will be set to the first frame in this animation.
- Source:
-
update()
-
Updates this animation. Called automatically by the AnimationManager.
- Source: