Applies animations over time, queues animations for later playback, mixes (crossfading) between animations, and applies multiple animations on top of each other (layering).

See Applying Animations in the Spine Runtimes Guide.

Static variables

@:value(new Animation("<empty>", new Array(0), 0))staticemptyAnimation:Animation = new Animation("<empty>", new Array(0), 0)

Constructor

new(data:AnimationStateData)

Creates an uninitialized AnimationState. The animation state data must be set before use.

Variables

@:value(new Array())tracks:Array<TrackEntry> = new Array()

@:value(new SnapshotArray())listeners:SnapshotArray<AnimationStateListener> = new SnapshotArray()

@:value(false)animationsChanged:Bool = false

@:value(new TrackEntryPool())trackEntryPool:Pool<TrackEntry> = new TrackEntryPool()

Methods

update(delta:Float):Void

Increments each track entry {@link TrackEntry#getTrackTime()}, setting queued animations as current if needed.

apply(skeleton:Skeleton):Bool

Poses the skeleton using the track entry animations. The animation state is not changed, so can be applied to multiple skeletons to pose them identically.

Returns:

True if any animations were applied.

clearTracks():Void

Removes all animations from all tracks, leaving skeletons in their current pose.

It may be desired to use {@link AnimationState#setEmptyAnimations(float)} to mix the skeletons back to the setup pose, rather than leaving them in their current pose.

clearTrack(trackIndex:Int):Void

Removes all animations from the track, leaving skeletons in their current pose.

It may be desired to use {@link AnimationState#setEmptyAnimation(int, float)} to mix the skeletons back to the setup pose, rather than leaving them in their current pose.

setAnimationByName(trackIndex:Int, animationName:String, loop:Bool):TrackEntry

Sets an animation by name.

See {@link #setAnimation(int, Animation, boolean)}.

setAnimation(trackIndex:Int, animation:Animation, loop:Bool):TrackEntry

Sets the current animation for a track, discarding any queued animations. If the formerly current track entry was never applied to a skeleton, it is replaced (not mixed from). @link TrackEntry#getTrackEnd()} determines when the track is cleared. @link AnimationStateListener#dispose(TrackEntry)} event occurs.

Parameters:

loop

If true, the animation will repeat. If false it will not, instead its last frame is applied if played beyond its duration. In either case {

Returns:

A track entry to allow further customization of animation playback. References to the track entry must not be kept after the {

addAnimationByName(trackIndex:Int, animationName:String, loop:Bool, delay:Float):TrackEntry

Queues an animation by name.

See {@link #addAnimation(int, Animation, boolean, float)}.

addAnimation(trackIndex:Int, animation:Animation, loop:Bool, delay:Float):TrackEntry

Adds an animation to be played after the current or last queued animation for a track. If the track is empty, it is equivalent to calling {@link #setAnimation(int, Animation, boolean)}. @link TrackEntry#getDelay()}. If <= 0, the delay set is the duration of the previous track entry

      minus any mix duration (from the {@link AnimationStateData}) plus the specified <code>delay</code> (ie the mix
      ends at (<code>delay</code> = 0) or before (<code>delay</code> < 0) the previous track entry duration). If the
      previous entry is looping, its next loop completion is used instead of its duration.

@link AnimationStateListener#dispose(TrackEntry)} event occurs.

Parameters:

delay

If > 0, sets {

Returns:

A track entry to allow further customization of animation playback. References to the track entry must not be kept after the {

setEmptyAnimation(trackIndex:Int, mixDuration:Float):TrackEntry

Sets an empty animation for a track, discarding any queued animations, and sets the track entry's {@link TrackEntry#getMixDuration()}. An empty animation has no timelines and serves as a placeholder for mixing in or out.

Mixing out is done by setting an empty animation with a mix duration using either {@link #setEmptyAnimation(int, float)}, {@link #setEmptyAnimations(float)}, or {@link #addEmptyAnimation(int, float, float)}. Mixing to an empty animation causes the previous animation to be applied less and less over the mix duration. Properties keyed in the previous animation transition to the value from lower tracks or to the setup pose value if no lower tracks key the property. A mix duration of 0 still mixes out over one frame.

Mixing in is done by first setting an empty animation, then adding an animation using {@link #addAnimation(int, Animation, boolean, float)} with the desired delay (an empty animation has a duration of 0) and on the returned track entry, set the {@link TrackEntry#setMixDuration(float)}. Mixing from an empty animation causes the new animation to be applied more and more over the mix duration. Properties keyed in the new animation transition from the value from lower tracks or from the setup pose value if no lower tracks key the property to the value keyed in the new animation.

addEmptyAnimation(trackIndex:Int, mixDuration:Float, delay:Float):TrackEntry

Adds an empty animation to be played after the current or last queued animation for a track, and sets the track entry's {@link TrackEntry#getMixDuration()}. If the track is empty, it is equivalent to calling {@link #setEmptyAnimation(int, float)}.

See {@link #setEmptyAnimation(int, float)}. @link TrackEntry#getDelay()}. If <= 0, the delay set is the duration of the previous track entry

      minus any mix duration plus the specified <code>delay</code> (ie the mix ends at (<code>delay</code> = 0) or
      before (<code>delay</code> < 0) the previous track entry duration). If the previous entry is looping, its next
      loop completion is used instead of its duration.

@link AnimationStateListener#dispose(TrackEntry)} event occurs.

Parameters:

delay

If > 0, sets {

Returns:

A track entry to allow further customization of animation playback. References to the track entry must not be kept after the {

setEmptyAnimations(mixDuration:Float):Void

Sets an empty animation for every track, discarding any queued animations, and mixes to it over the specified mix duration.

clearNext(entry:TrackEntry):Void

Removes the {@link TrackEntry#getNext() next entry} and all entries after it for the specified entry.

getCurrent(trackIndex:Int):TrackEntry

Returns the track entry for the animation currently playing on the track, or null if no animation is currently playing.

addListener(listener:AnimationStateListener):Void

Adds a listener to receive events for all track entries.

removeListener(listener:AnimationStateListener):Void

Removes the listener added with {@link #addListener(AnimationStateListener)}.

clearListeners():Void

Removes all listeners added with {@link #addListener(AnimationStateListener)}.

clearListenerNotifications():Void

Discards all listener notifications that have not yet been delivered. This can be useful to call from an {@link AnimationStateListener} when it is known that further notifications that may have been already queued for delivery are not wanted because new animations are being set.

getTimeScale():Float

Multiplier for the delta time when the animation state is updated, causing time for all animations and mixes to play slower or faster. Defaults to 1.

See TrackEntry {@link TrackEntry#getTimeScale()} for affecting a single animation.

getData():AnimationStateData

The AnimationStateData to look up mix durations.

getTracks():Array<TrackEntry>

The list of tracks that have had animations, which may contain null entries for tracks that currently have no animation.