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.
Constructor
Variables
timeScale:Float = 1.0
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 TrackEntry.timeScale
for affecting a single animation.
finaltracks:Array<Null<TrackEntry>> = new Array<Null<TrackEntry>>()
The list of tracks that currently have animations, which may contain null entries.
Methods
addAnimation(trackIndex:Int, animationName:String, loop:Bool, delay:Float):TrackEntry
Queues an animation by name.
See also:
addAnimationWith
.
addAnimationWith(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 setAnimationWith
.
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 AnimationStateListener.dispose
event occurs.
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
TrackEntry.mixDuration
. If the track is empty, it is equivalent to calling setEmptyAnimation
.
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 AnimationStateListener.dispose
event occurs.
See also:
setEmptyAnimation
.
addListener(listener:AnimationStateListener):Void
Adds a listener to receive events for all track entries.
apply(skeleton:Skeleton):Bool
Poses the skeleton using the track entry animations. There are no side effects other than invoking listeners, so the animation state can be applied to multiple skeletons to pose them identically.
Returns:
True if any animations were applied.
clearListenerNotifications():Void
Discards all listener notifications that have not yet been delivered. This can be useful to call from an
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.
clearTrack(trackIndex:Int):Void
Removes all animations from the track, leaving skeletons in their current pose.
It may be desired to use AnimationState.setEmptyAnimation
to mix the skeletons back to the setup pose,
rather than leaving them in their current pose.
clearTracks():Void
Removes all animations from all tracks, leaving skeletons in their current pose.
It may be desired to use AnimationState.setEmptyAnimation
to mix the skeletons back to the setup pose,
rather than leaving them in their current pose.
getCurrent(trackIndex:Int):Null<TrackEntry>
Returns the track entry for the animation currently playing on the track, or null if no animation is currently playing.
setAnimation(trackIndex:Int, animationName:String, loop:Bool):TrackEntry
Sets an animation by name.
See also:
setAnimationWith
.
setAnimationWith(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).
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 AnimationStateListener.dispose
event occurs.
setEmptyAnimation(trackIndex:Int, mixDuration:Float):TrackEntry
Sets an empty animation for a track, discarding any queued animations, and sets the track entry's
TrackEntry.mixduration
. 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 setEmptyAnimation
,
setEmptyAnimations
, or addEmptyAnimation
. 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
addAnimation
and on the returned track entry, set the
TrackEntry.mixDuration
. 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.
setEmptyAnimations(mixDuration:Float):Void
Sets an empty animation for every track, discarding any queued animations, and mixes to it over the specified mix duration.
update(delta:Float):Void
Increments each track entry TrackEntry.trackTime
, setting queued animations as current if needed.