Struct rusty_spine::AnimationState

source ·
pub struct AnimationState { /* private fields */ }
Expand description

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.

Spine API Reference

Implementations§

source§

impl AnimationState

source

pub fn new(animation_state_data: Arc<AnimationStateData>) -> Self

source

pub fn update(&mut self, delta: f32)

source

pub fn apply(&self, skeleton: &mut Skeleton) -> bool

source

pub fn clear_tracks(&mut self)

Clears all animations in all track entries in this animation state.

source

pub fn clear_track(&mut self, track_index: usize)

Clears animations for the given track entry index in this animation state.

source

pub unsafe fn set_animation_by_name_unchecked( &mut self, track_index: usize, animation_name: &str, looping: bool ) -> CTmpMut<'_, Self, TrackEntry>

Sets the animation for the given track by name, clearing any queued tracks, and returning the track index. If the track index doesn’t exist then it will be created.

§Safety

This function should only be called with valid animation names. It is faster than the safe alternative, AnimationState::set_animation_by_name, but will likely segfault if the animation does not exist.

source

pub fn set_animation_by_name( &mut self, track_index: usize, animation_name: &str, looping: bool ) -> Result<CTmpMut<'_, Self, TrackEntry>, SpineError>

Sets the animation for the given track by name, clearing any queued tracks, and returning the track index. If the track index doesn’t exist then it will be created.

§Errors

Returns SpineError::NotFound if an animation doesn’t exist with the given name.

source

pub fn set_animation( &mut self, track_index: usize, animation: &Animation, looping: bool ) -> CTmpMut<'_, Self, TrackEntry>

Sets the animation for the given track, clearning any queued tracks, and returning the track index. If the track index doesn’t exist then it will be created.

source

pub unsafe fn add_animation_by_name_unchecked( &mut self, track_index: usize, animation_name: &str, looping: bool, delay: f32 ) -> CTmpMut<'_, Self, TrackEntry>

Queues the animation in the given track by name, returning the track index. If the track index doesn’t exist then it will be created.

§Safety

This function should only be called with valid animation names. It is faster than the safe alternative, AnimationState::add_animation_by_name, but will likely segfault if the animation does not exist.

source

pub fn add_animation_by_name( &mut self, track_index: usize, animation_name: &str, looping: bool, delay: f32 ) -> Result<CTmpMut<'_, Self, TrackEntry>, SpineError>

Queues the animation in the given track by name, returning the track index. If the track index doesn’t exist then it will be created.

§Errors

Returns SpineError::NotFound if an animation doesn’t exist with the given name.

source

pub fn add_animation( &mut self, track_index: usize, animation: &Animation, looping: bool, delay: f32 ) -> CTmpMut<'_, Self, TrackEntry>

Queues the animation in the given track, returning the track index. If the track index doesn’t exist then it will be created.

source

pub fn set_empty_animation( &mut self, track_index: usize, mix_duration: f32 ) -> CTmpMut<'_, Self, TrackEntry>

source

pub fn add_empty_animation( &mut self, track_index: usize, mix_duration: f32, delay: f32 ) -> CTmpMut<'_, Self, TrackEntry>

source

pub fn set_empty_animations(&mut self, mix_duration: f32)

source

pub fn get_current( &self, track_index: usize ) -> Option<CTmpRef<'_, Self, TrackEntry>>

source

pub fn set_listener<F>(&mut self, listener: F)
where F: Fn(&AnimationState, AnimationEvent<'_>) + 'static,

Set the event listener on this animation state. An animation state can only have one event listener at a time.

animation_state.set_listener(|_, animation_event| match animation_event {
    AnimationEvent::Start { track_entry } => {
        println!("Animation {} started!", track_entry.track_index());
    }
    AnimationEvent::Interrupt { track_entry } => {
        println!("Animation {} interrupted!", track_entry.track_index());
    }
    AnimationEvent::End { track_entry } => {
        println!("Animation {} ended!", track_entry.track_index());
    }
    AnimationEvent::Complete { track_entry } => {
        println!("Animation {} completed!", track_entry.track_index());
    }
    AnimationEvent::Dispose { track_entry } => {
        println!("Animation {} disposed!", track_entry.track_index());
    }
    AnimationEvent::Event {
        track_entry,
        name,
        int,
        float,
        string,
        audio_path,
        volume,
        balance,
        ..
    } => {
        println!("Animation {} event!", track_entry.track_index());
        println!("  Name: {name}");
        println!("  Integer: {int}");
        println!("  Float: {float}");
        if !string.is_empty() {
            println!("  String: \"{string}\"");
        }
        if !audio_path.is_empty() {
            println!("  Audio: \"{audio_path}\"");
            println!("    Volume: {volume}");
            println!("    Balance: {balance}");
        }
    }
});
source

pub fn clear_listener_notifications(&mut self)

source

pub fn clear_next(&mut self, entry: &TrackEntry)

source

pub fn data(&self) -> CTmpRef<'_, Self, AnimationStateData>

The AnimationStateData to look up mix durations.

source

pub fn data_mut(&mut self) -> CTmpMut<'_, Self, AnimationStateData>

source

pub fn tracks_count(&self) -> usize

source

pub fn tracks( &self ) -> CTmpPtrNullableIterator<'_, AnimationState, TrackEntry, spTrackEntry>

source

pub fn tracks_mut( &mut self ) -> CTmpMutNullableIterator<'_, AnimationState, TrackEntry, spTrackEntry>

source

pub fn track_at_index( &self, index: usize ) -> Option<CTmpRef<'_, Self, TrackEntry>>

source

pub fn track_at_index_mut( &mut self, index: usize ) -> Option<CTmpMut<'_, Self, TrackEntry>>

source

pub fn timescale(&self) -> f32

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::timescale for affecting a single animation.

source

pub fn set_timescale(&mut self, value: f32)

Set the timescale, see timescale.

source

pub fn renderer_object(&self) -> RendererObject<'_>

source

pub fn dispose_statics()

source

pub const fn c_ptr(&self) -> *mut spAnimationState

Get a pointer to the underlying spine-c type.

Trait Implementations§

source§

impl Debug for AnimationState

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drop for AnimationState

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl NewFromPtr<spAnimationState> for AnimationState

source§

unsafe fn new_from_ptr(c_animation_state: *mut spAnimationState) -> Self

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.