AnimationState

spine.AnimationState (Class)

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 Members

spine
emptyAnimation: Animation

Instance Members



spine
animationsChanged: Bool


spine
update(delta: Float): Void

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

Name Type
delta Float

spine
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.

Name Type
skeleton Skeleton
Returns Description
Bool True if any animations were applied.

spine
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.


spine
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.

Name Type
trackIndex Int

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

Sets an animation by name.

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

Name Type
trackIndex Int
animationName String
loop Bool
Returns
TrackEntry

spine
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.

Name Type Description
trackIndex Int
animation Animation
loop Bool 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 Description
TrackEntry A track entry to allow further customization of animation playback. References to the track entry must not be kept after the {

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

Queues an animation by name.

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

Name Type
trackIndex Int
animationName String
loop Bool
delay Float
Returns
TrackEntry

spine
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 AnimationStateData}) plus the specified delay (ie the mix ends at (delay = 0) or before (delay < 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.

Name Type Description
trackIndex Int
animation Animation
loop Bool
delay Float If > 0, sets {
Returns Description
TrackEntry A track entry to allow further customization of animation playback. References to the track entry must not be kept after the {

spine
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.

Name Type
trackIndex Int
mixDuration Float
Returns
TrackEntry

spine
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 AnimationStateListener#dispose(TrackEntry)} event occurs.

Name Type Description
trackIndex Int
mixDuration Float
delay Float If > 0, sets {
Returns Description
TrackEntry A track entry to allow further customization of animation playback. References to the track entry must not be kept after the {

spine
setEmptyAnimations(mixDuration: Float): Void

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

Name Type
mixDuration Float

spine
clearNext(entry: TrackEntry): Void

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

Name Type
entry TrackEntry

spine
handleAnimationsChanged(): Void

spine
getCurrent(trackIndex: Int): TrackEntry

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

Name Type
trackIndex Int
Returns
TrackEntry

spine
addListener(listener: AnimationStateListener): Void

Adds a listener to receive events for all track entries.

Name Type
listener AnimationStateListener

spine
removeListener(listener: AnimationStateListener): Void

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

Name Type
listener AnimationStateListener

spine
clearListeners(): Void

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


spine
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.


spine
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. | Returns | |---------| | [Float](/api-docs/clay-native/Float/) |


spine
setTimeScale(timeScale: Float): Void
Name Type
timeScale Float

spine
getData(): AnimationStateData

The AnimationStateData to look up mix durations.

Returns
AnimationStateData

spine
setData(data: AnimationStateData): Void
Name Type
data AnimationStateData

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

Returns
spine.support.utils.Array<TrackEntry>

spine
toString(): String
Returns
String

spine
new(data: AnimationStateData): Void

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

Name Type
data AnimationStateData

Private Members

spine
SUBSEQUENT: Int
  1. A previously applied timeline has set this property.
    Result: Mix from the current pose to the timeline pose.

spine
FIRST: Int
  1. This is the first timeline to set this property.
  2. The next track entry applied after this one does not have a timeline to set this property.
    Result: Mix from the setup pose to the timeline pose.

spine
HOLD_SUBSEQUENT: Int
  1. A previously applied timeline has set this property.
  2. The next track entry to be applied does have a timeline to set this property.
  3. The next track entry after that one does not have a timeline to set this property.
    Result: Mix from the current pose to the timeline pose, but do not mix out. This avoids "dipping" when crossfading animations that key the same property. A subsequent timeline will set this property using a mix.

spine
HOLD_FIRST: Int
  1. This is the first timeline to set this property.
  2. The next track entry to be applied does have a timeline to set this property.
  3. The next track entry after that one does not have a timeline to set this property.
    Result: Mix from the setup pose to the timeline pose, but do not mix out. This avoids "dipping" when crossfading animations that key the same property. A subsequent timeline will set this property using a mix.

spine
HOLD_MIX: Int
  1. This is the first timeline to set this property.
  2. The next track entry to be applied does have a timeline to set this property.
  3. The next track entry after that one does have a timeline to set this property.
  4. timelineHoldMix stores the first subsequent track entry that does not have a timeline to set this property.
    Result: The same as HOLD except the mix percentage from the timelineHoldMix track entry is used. This handles when more than 2 track entries in a row have a timeline that sets the same property.
    Eg, A -> B -> C -> D where A, B, and C have a timeline setting same property, but D does not. When A is applied, to avoid "dipping" A is not mixed out, however D (the first entry that doesn't set the property) mixing in is used to mix out A (which affects B and C). Without using D to mix out, A would be applied fully until mixing completes, then snap to the mixed out position.

spine
SETUP: Int

spine
CURRENT: Int



spine
queue: EventQueue


spine
timeScale: Float

spine
unkeyedState: Int

spine
updateMixingFrom(to: TrackEntry, delta: Float): Bool

Returns true when all mixing from entries are complete.

Name Type
to TrackEntry
delta Float
Returns
Bool

spine
applyMixingFrom(to: TrackEntry, skeleton: Skeleton, blend: MixBlend): Float
Name Type
to TrackEntry
skeleton Skeleton
blend MixBlend
Returns
Float

spine
applyAttachmentTimeline(timeline: AttachmentTimeline, skeleton: Skeleton, time: Float, blend: MixBlend, attachments: Bool): Void

Applies the attachment timeline and sets {@link Slot#attachmentState}.

Name Type Description
timeline AttachmentTimeline
skeleton Skeleton
time Float
blend MixBlend
attachments Bool False when: 1) the attachment timeline is mixing out, 2) mix < attachmentThreshold, and 3) the timeline is not the last timeline to set the slot's attachment. In that case the timeline is applied only so subsequent timelines see any deform.

spine
setAttachment(skeleton: Skeleton, slot: Slot, attachmentName: String, attachments: Bool): Void
Name Type
skeleton Skeleton
slot Slot
attachmentName String
attachments Bool

spine
applyRotateTimeline(timeline: RotateTimeline, skeleton: Skeleton, time: Float, alpha: Float, blend: MixBlend, timelinesRotation: spine.support.utils.FloatArray, i: Int, firstFrame: Bool): Void

Applies the rotate timeline, mixing with the current pose while keeping the same rotation direction chosen as the shortest the first time the mixing was applied.

Name Type
timeline RotateTimeline
skeleton Skeleton
time Float
alpha Float
blend MixBlend
timelinesRotation spine.support.utils.FloatArray
i Int
firstFrame Bool

spine
queueEvents(entry: TrackEntry, animationTime: Float): Void
Name Type
entry TrackEntry
animationTime Float

spine
setCurrent(index: Int, current: TrackEntry, interrupt: Bool): Void
Name Type
index Int
current TrackEntry
interrupt Bool

spine
expandToIndex(index: Int): TrackEntry
Name Type
index Int
Returns
TrackEntry

spine
trackEntry(trackIndex: Int, animation: Animation, loop: Bool, last: TrackEntry): TrackEntry
Name Type
trackIndex Int
animation Animation
loop Bool
last TrackEntry
Returns
TrackEntry

spine
computeHold(entry: TrackEntry): Void
Name Type
entry TrackEntry