AnimationLayer

AnimationLayer

Animation layers are essentially independent state machines, managed by a single AnimationManager. Each maintains a set of possible
"steady states" - main states that the layer can be in. The layer can only be in one state at any given time. It may transition between
states, provided that a path is defined for transition from the current state to the desired one. *

Constructor

new AnimationLayer(name, id, world)

Parameters:
Name Type Description
name string

Name of layer

id string

Id of layer

world World

world object that the layer is being added to

Members

world

set the world object, called when containing Animation Component is attached or detached from an entity

Methods

clearCurrentState()

Set the currently playing state on this layer to null.

clone() → {AnimationLayer}

getCurrentSourceData()

getCurrentState() → {AbstractState}

Get the current state

getStateById(id) → {AbstractState}

Get the current state by id.

Parameters:
Name Type Description
id string

getStateByName(name) → {AbstractState}

Get the current state by name.

Parameters:
Name Type Description
name string

getStates() → {Array.<string>}

Get available states for layer

getTransitions() → {Array.<string>}

Get available transitions for current State

setBlendWeight(weight)

Sets the blend weight of a layer. This will not affect the base
layer in the animation component.

Parameters:
Name Type Description
weight number

Should be between 0 and 1 and will be clamped

setCurrentState(state, rewindopt, globalTimeopt, finishCallbackopt)

Sets the current state to the given state. Generally for transitional state use.

Parameters:
Name Type Attributes Default Description
state AbstractState

our new state. If null, then no state is currently set on this layer.

rewind boolean <optional>
false

if true, the clip(s) in the given state will be rewound by setting its start time to the current time and setting it active.

globalTime number <optional>
this._world.time

start time for the transition, defaults to current time

finishCallback function <optional>

If the target state has a limited number of repeats, this callback is called when the animation finishes.

setCurrentStateById(id, rewindopt, globalTimeopt, callback)

Set the current state by state id.

Parameters:
Name Type Attributes Default Description
id string
rewind boolean <optional>
false

if true, the clip(s) in the given state will be rewound by setting its start time to the current time and setting it active.

globalTime number <optional>
this._world.time

start time for the transition, defaults to current time

callback function

If the target state has a limited number of repeats, this callback is called when the animation finishes.

setCurrentStateByName(stateName, rewind, globalTimeopt) → {boolean}

Force the current state of the machine to the state with the given name.

Parameters:
Name Type Attributes Default Description
stateName AbstractState

the name of our state. If null, or is not present in this state machine, the current state is not changed.

rewind boolean

if true, the clip(s) in the given state will be rewound by setting its start time to the current time and setting it active.

globalTime number <optional>
this._world.time

start time for the transition, defaults to current time

setState(stateKey, state)

Add a state to the layer with the associated stateKey

Parameters:
Name Type Description
stateKey string
state SteadyState

transitionTo(state, globalTimeopt, finishCallbackopt, doSwitchIfTransitioningopt) → {boolean}

Transition the layer to another state. The transition must be specified either on the state or on the layer (as a general transition), see FileFormat spec for more info.

If the layer is currently transitioning, the transition is ignored unless doSwitchIfTransitiong is set to true, in which case the animState is immediately switched with no transition.

Parameters:
Name Type Attributes Default Description
state string

the state Id to transition to

globalTime number <optional>
this._world.time

start time for the transition, defaults to current time

finishCallback function <optional>

If the target state has a limited number of repeats, this callback is called when the animation finishes.

doSwitchIfTransitioning boolean <optional>
false

if true and the layer is currently transition, switch immediately to the given state. Otherwise the transition is ignored and false is returned.