Class: Phaser.Animation
Constructor
new Animation(game, parent, name, frameData, frames, frameRate, loop)
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 | Argument | Default | 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.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. | ||
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. |
- Source code: animation/Animation.js (Line 22)
Public Properties
- Source code: animation/Animation.js (Line 125)
- Source code: animation/Animation.js (Line 58)
- Source code: animation/Animation.js (Line 800)
- Source code: animation/Animation.js (Line 739)
- Source code: animation/Animation.js (Line 726)
- Source code: animation/Animation.js (Line 29)
- Source code: animation/Animation.js (Line 80)
- Source code: animation/Animation.js (Line 92)
- Source code: animation/Animation.js (Line 86)
- Source code: animation/Animation.js (Line 157)
- Source code: animation/Animation.js (Line 74)
- Source code: animation/Animation.js (Line 63)
- Source code: animation/Animation.js (Line 68)
- Source code: animation/Animation.js (Line 46)
- Source code: animation/Animation.js (Line 146)
- Source code: animation/Animation.js (Line 151)
- Source code: animation/Animation.js (Line 130)
- Phaser.Signal | null
- Source code: animation/Animation.js (Line 141)
- Source code: animation/Animation.js (Line 672)
- Source code: animation/Animation.js (Line 706)
- Source code: animation/Animation.js (Line 777)
currentFrame : Phaser.Frame
The currently displayed frame of the Animation.
delay : number
The delay in ms between each frame of the Animation, based on the given frameRate.
enableUpdate : boolean
Gets or sets if this animation will dispatch the onUpdate events upon changing frame.
frame : number
Gets or sets the current frame index and updates the Texture Cache for display.
[readonly] frameTotal : number
The total number of frames in the currently loaded FrameData, or -1 if no FrameData is loaded.
game : Phaser.Game
A reference to the currently running Game.
isFinished : boolean
The finished state of the Animation. Set to true once playback completes, false during playback.
isPaused : boolean
The paused state of the Animation.
isPlaying : boolean
The playing state of the Animation. Set to false once playback completes, true during playback.
isReversed : boolean
Indicates if the animation will play backwards.
killOnComplete : boolean
Should the parent of this Animation be killed when the animation completes?
loop : boolean
The loop state of the Animation.
loopCount : number
The number of times the animation has looped since it was last started.
name : string
The user defined name given to this Animation.
onComplete : Phaser.Signal
This event is dispatched when this Animation completes playback. If the animation is set to loop this is never fired, listen for onLoop instead.
onLoop : Phaser.Signal
This event is dispatched when this Animation loops.
onStart : Phaser.Signal
This event is dispatched when this Animation starts playback.
onUpdate : Phaser.Signal | null
This event is dispatched when the Animation changes frame.
By default this event is disabled due to its intensive nature. Enable it with: Animation.enableUpdate = true
.
Note that the event is only dispatched with the current frame. In a low-FPS environment Animations
will automatically frame-skip to try and claw back time, so do not base your code on expecting to
receive a perfectly sequential set of frames from this event.
Type
paused : boolean
Gets and sets the paused state of this Animation.
reversed : boolean
Gets and sets the isReversed state of this Animation.
speed : number
Gets or sets the current speed of the animation in frames per second. Changing this in a playing animation will take effect from the next frame. Value must be greater than 0.
Public Methods
- Source code: animation/Animation.js (Line 828)
- Source code: animation/Animation.js (Line 642)
- Source code: animation/Animation.js (Line 608)
- Source code: animation/Animation.js (Line 531)
- Source code: animation/Animation.js (Line 365)
- Source code: animation/Animation.js (Line 379)
- A reference to this Animation instance.
- Source code: animation/Animation.js (Line 167)
- Source code: animation/Animation.js (Line 563)
- Source code: animation/Animation.js (Line 218)
- Source code: animation/Animation.js (Line 246)
- Source code: animation/Animation.js (Line 260)
- Source code: animation/Animation.js (Line 276)
- Source code: animation/Animation.js (Line 334)
- Source code: animation/Animation.js (Line 393)
- Source code: animation/Animation.js (Line 595)
<static> generateFrameNames(prefix, start, stop, suffix, zeroPad) → {Array.<string>}
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: 'explosion_0001-large' to 'explosion0030-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'. | ||
start | number | The number to start sequentially counting from. If your frames are named 'explosion_0001' to 'explosion_0034' the start is 1. | ||
stop | number | The number to count to. If your frames are named 'explosion_0001' to 'explosion_0034' the stop value 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 zeros to pad the min and max values with. If your frames are named 'explosion_0001' to 'explosion_0034' then the zeroPad is 4. |
Returns
An array of framenames.
complete()
Called internally when the animation finishes playback.
Sets the isPlaying and isFinished states and dispatches the onAnimationComplete event if it exists on the parent and local onComplete event.
destroy()
Cleans up this animation ready for deletion. Nulls all values and references.
next(quantity)
Advances by the given number of frames in the Animation, taking the loop value into consideration.
Parameters
Name | Type | Argument | Default | Description |
---|---|---|---|---|
quantity | number | <optional> | 1 | The number of frames to advance. |
onPause()
Called when the Game enters a paused state.
onResume()
Called when the Game resumes from a paused state.
play(frameRate, loop, killOnComplete) → {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> | 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. |
Returns
previous(quantity)
Moves backwards the given number of frames in the Animation, taking the loop value into consideration.
Parameters
Name | Type | Argument | Default | Description |
---|---|---|---|---|
quantity | number | <optional> | 1 | The number of frames to move back. |
restart()
Sets this animation back to the first frame and restarts the animation.
reverse() → {Phaser.Animation}
Reverses the animation direction.
Returns
The animation instance.
reverseOnce() → {Phaser.Animation}
Reverses the animation direction for the current/next animation only
Once the onComplete event is called this method will be called again and revert
the reversed state.
Returns
The animation instance.
setFrame(frameId, useLocalFrameIndex)
Sets this animations playback to a given frame with the given ID.
Parameters
Name | Type | Argument | Default | Description |
---|---|---|---|---|
frameId | string | number | <optional> | The identifier of the frame to set. Can be the name of the frame, the sprite index of the frame, or the animation-local frame index. | |
useLocalFrameIndex | boolean | <optional> | false | If you provide a number for frameId, should it use the numeric indexes of the frameData, or the 0-indexed frame index local to the animation. |
stop(resetFrame, dispatchComplete)
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.
If dispatchComplete
is true it will dispatch the complete events, otherwise they'll be ignored.
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. |
dispatchComplete | boolean | <optional> | false | Dispatch the Animation.onComplete and parent.onAnimationComplete events? |
update()
Updates this animation. Called automatically by the AnimationManager.
updateFrameData(frameData)
Changes the FrameData object this Animation is using.
Parameters
Name | Type | Description |
---|---|---|
frameData | Phaser.FrameData | The FrameData object that contains all frames used by this Animation. |
© 2016 Richard Davey, Photon Storm Ltd.
Licensed under the MIT License.
http://phaser.io/docs/2.6.2/Phaser.Animation.html