Class: Animation

Phaser.Animations. Animation

A Frame based Animation.

This consists of a key, some default values (like the frame rate) and a bunch of Frame objects.

The Animation Manager creates these. Game Objects don't own an instance of these directly. Game Objects have the Animation Component, which are like playheads to global Animations (these objects) So multiple Game Objects can have playheads all pointing to this one Animation instance.


new Animation(manager, key, config)

Parameters:
Name Type Description
manager Phaser.Animations.AnimationManager

A reference to the global Animation Manager

key string

The unique identifying string for this animation.

config Phaser.Types.Animations.Animation

The Animation configuration.

Since: 3.0.0
Source: src/animations/Animation.js (Line 15)

Extends

Members


delay :integer

The delay in ms before the playback will begin.

Type:
  • integer
Since: 3.0.0
Default Value:
  • 0
Source: src/animations/Animation.js (Line 147)

duration :integer

How long the animation should play for, in milliseconds. If the frameRate property has been set then it overrides this value, otherwise the frameRate is derived from duration.

Type:
  • integer
Since: 3.0.0
Source: src/animations/Animation.js (Line 96)

frameRate :integer

The frame rate of playback in frames per second (default 24 if duration is null)

Type:
  • integer
Since: 3.0.0
Default Value:
  • 24
Source: src/animations/Animation.js (Line 86)

frames :Array.<Phaser.Animations.AnimationFrame>

Extract all the frame data into the frames array.

Type:
Since: 3.0.0
Source: src/animations/Animation.js (Line 73)

hideOnComplete :boolean

Should the GameObject's visible property be set to false when the animation finishes?

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

key :string

The unique identifying string for this animation.

Type:
  • string
Since: 3.0.0
Source: src/animations/Animation.js (Line 54)

manager :Phaser.Animations.AnimationManager

A reference to the global Animation Manager.

Type:
Since: 3.0.0
Source: src/animations/Animation.js (Line 45)

msPerFrame :integer

How many ms per frame, not including frame specific modifiers.

Type:
  • integer
Since: 3.0.0
Source: src/animations/Animation.js (Line 128)

paused :boolean

Global pause. All Game Objects using this Animation instance are impacted by this property.

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

repeat :integer

Number of times to repeat the animation. Set to -1 to repeat forever.

Type:
  • integer
Since: 3.0.0
Default Value:
  • 0
Source: src/animations/Animation.js (Line 157)

repeatDelay :integer

The delay in ms before the a repeat play starts.

Type:
  • integer
Since: 3.0.0
Default Value:
  • 0
Source: src/animations/Animation.js (Line 167)

showOnStart :boolean

Should the GameObject's visible property be set to true when the animation starts to play?

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

skipMissedFrames :boolean

Skip frames if the time lags, or always advanced anyway?

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

type :string

A frame based animation (as opposed to a bone based animation)

Type:
  • string
Since: 3.0.0
Default Value:
  • frame
Source: src/animations/Animation.js (Line 63)

yoyo :boolean

Should the animation yoyo (reverse back down to the start) before repeating?

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

Methods


addFrame(config)

Add frames to the end of the animation.

Parameters:
Name Type Description
config string | Array.<Phaser.Types.Animations.AnimationFrame>

[description]

Since: 3.0.0
Source: src/animations/Animation.js (Line 221)
Returns:

This Animation object.

Type
Phaser.Animations.Animation

addFrameAt(index, config)

Add frame/s into the animation.

Parameters:
Name Type Description
index integer

The index to insert the frame at within the animation.

config string | Array.<Phaser.Types.Animations.AnimationFrame>

[description]

Since: 3.0.0
Source: src/animations/Animation.js (Line 236)
Returns:

This Animation object.

Type
Phaser.Animations.Animation

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

checkFrame(index)

Check if the given frame index is valid.

Parameters:
Name Type Description
index integer

The index to be checked.

Since: 3.0.0
Source: src/animations/Animation.js (Line 275)
Returns:

true if the index is valid, otherwise false.

Type
boolean

<protected> completeAnimation(component)

[description]

Parameters:
Name Type Description
component Phaser.GameObjects.Components.Animation

[description]

Since: 3.0.0
Source: src/animations/Animation.js (Line 290)

destroy()

[description]

Since: 3.0.0
Overrides:
Source: src/animations/Animation.js (Line 908)

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

<protected> getFirstTick(component [, includeDelay])

[description]

Parameters:
Name Type Argument Default Description
component Phaser.GameObjects.Components.Animation

[description]

includeDelay boolean <optional>
true

[description]

Since: 3.0.0
Source: src/animations/Animation.js (Line 309)

<protected> getFrameAt(index)

Returns the AnimationFrame at the provided index

Parameters:
Name Type Description
index integer

The index in the AnimationFrame array

Since: 3.0.0
Source: src/animations/Animation.js (Line 333)
Returns:

The frame at the index provided from the animation sequence

Type
Phaser.Animations.AnimationFrame

getFrameByProgress(value)

Returns the frame closest to the given progress value between 0 and 1.

Parameters:
Name Type Description
value number

A value between 0 and 1.

Since: 3.4.0
Source: src/animations/Animation.js (Line 512)
Returns:

The frame closest to the given progress value.

Type
Phaser.Animations.AnimationFrame

getFrames(textureManager, frames [, defaultTextureKey])

[description]

Parameters:
Name Type Argument Description
textureManager Phaser.Textures.TextureManager

[description]

frames string | Array.<Phaser.Types.Animations.AnimationFrame>

[description]

defaultTextureKey string <optional>

[description]

Since: 3.0.0
Source: src/animations/Animation.js (Line 349)
Returns:

[description]

Type
Array.<Phaser.Animations.AnimationFrame>

getLastFrame()

Returns the animation last frame.

Since: 3.12.0
Source: src/animations/Animation.js (Line 613)
Returns:

component - The Animation Last Frame.

Type
Phaser.Animations.AnimationFrame

getNextTick(component)

[description]

Parameters:
Name Type Description
component Phaser.GameObjects.Components.Animation

[description]

Since: 3.0.0
Source: src/animations/Animation.js (Line 451)

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

nextFrame(component)

Advance the animation frame.

Parameters:
Name Type Description
component Phaser.GameObjects.Components.Animation

The Animation Component to advance.

Since: 3.0.0
Source: src/animations/Animation.js (Line 529)

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

pause()

[description]

Since: 3.0.0
Source: src/animations/Animation.js (Line 878)
Returns:

This Animation object.

Type
Phaser.Animations.Animation

previousFrame(component)

[description]

Parameters:
Name Type Description
component Phaser.GameObjects.Components.Animation

[description]

Since: 3.0.0
Source: src/animations/Animation.js (Line 626)

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

removeFrame(frame)

[description]

Parameters:
Name Type Description
frame Phaser.Animations.AnimationFrame

[description]

Since: 3.0.0
Source: src/animations/Animation.js (Line 689)
Returns:

This Animation object.

Type
Phaser.Animations.Animation

removeFrameAt(index)

Removes a frame from the AnimationFrame array at the provided index and updates the animation accordingly.

Parameters:
Name Type Description
index integer

The index in the AnimationFrame array

Since: 3.0.0
Source: src/animations/Animation.js (Line 711)
Returns:

This Animation object.

Type
Phaser.Animations.Animation

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

repeatAnimation(component)

[description]

Parameters:
Name Type Description
component Phaser.GameObjects.Components.Animation

[description]

Since: 3.0.0
Source: src/animations/Animation.js (Line 731)
Fires:

resume()

[description]

Since: 3.0.0
Source: src/animations/Animation.js (Line 893)
Returns:

This Animation object.

Type
Phaser.Animations.Animation

setFrame(component)

Sets the texture frame the animation uses for rendering.

Parameters:
Name Type Description
component Phaser.GameObjects.Components.Animation

[description]

Since: 3.0.0
Source: src/animations/Animation.js (Line 779)

shutdown()

Removes all listeners.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 31)

toJSON()

Converts the animation data to JSON.

Since: 3.0.0
Source: src/animations/Animation.js (Line 800)
Returns:

[description]

Type
Phaser.Types.Animations.JSONAnimation

updateFrameSequence()

[description]

Since: 3.0.0
Source: src/animations/Animation.js (Line 833)
Returns:

This Animation object.

Type
Phaser.Animations.Animation