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.
Implementations§
source§impl AnimationState
impl AnimationState
pub fn new(animation_state_data: Arc<AnimationStateData>) -> Self
pub fn update(&mut self, delta: f32)
pub fn apply(&self, skeleton: &mut Skeleton) -> bool
sourcepub fn clear_tracks(&mut self)
pub fn clear_tracks(&mut self)
Clears all animations in all track entries in this animation state.
sourcepub fn clear_track(&mut self, track_index: usize)
pub fn clear_track(&mut self, track_index: usize)
Clears animations for the given track entry index in this animation state.
sourcepub unsafe fn set_animation_by_name_unchecked(
&mut self,
track_index: usize,
animation_name: &str,
looping: bool
) -> CTmpMut<'_, Self, TrackEntry>
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.
sourcepub fn set_animation_by_name(
&mut self,
track_index: usize,
animation_name: &str,
looping: bool
) -> Result<CTmpMut<'_, Self, TrackEntry>, SpineError>
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.
sourcepub fn set_animation(
&mut self,
track_index: usize,
animation: &Animation,
looping: bool
) -> CTmpMut<'_, Self, TrackEntry>
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.
sourcepub unsafe fn add_animation_by_name_unchecked(
&mut self,
track_index: usize,
animation_name: &str,
looping: bool,
delay: f32
) -> CTmpMut<'_, Self, TrackEntry>
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.
sourcepub fn add_animation_by_name(
&mut self,
track_index: usize,
animation_name: &str,
looping: bool,
delay: f32
) -> Result<CTmpMut<'_, Self, TrackEntry>, SpineError>
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.
sourcepub fn add_animation(
&mut self,
track_index: usize,
animation: &Animation,
looping: bool,
delay: f32
) -> CTmpMut<'_, Self, TrackEntry>
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.
pub fn set_empty_animation( &mut self, track_index: usize, mix_duration: f32 ) -> CTmpMut<'_, Self, TrackEntry>
pub fn add_empty_animation( &mut self, track_index: usize, mix_duration: f32, delay: f32 ) -> CTmpMut<'_, Self, TrackEntry>
pub fn set_empty_animations(&mut self, mix_duration: f32)
pub fn get_current( &self, track_index: usize ) -> Option<CTmpRef<'_, Self, TrackEntry>>
sourcepub fn set_listener<F>(&mut self, listener: F)
pub fn set_listener<F>(&mut self, listener: F)
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}");
}
}
});
pub fn clear_listener_notifications(&mut self)
pub fn clear_next(&mut self, entry: &TrackEntry)
sourcepub fn data(&self) -> CTmpRef<'_, Self, AnimationStateData>
pub fn data(&self) -> CTmpRef<'_, Self, AnimationStateData>
The AnimationStateData
to look up mix durations.
pub fn data_mut(&mut self) -> CTmpMut<'_, Self, AnimationStateData>
pub fn tracks_count(&self) -> usize
pub fn tracks( &self ) -> CTmpPtrNullableIterator<'_, AnimationState, TrackEntry, spTrackEntry> ⓘ
pub fn tracks_mut( &mut self ) -> CTmpMutNullableIterator<'_, AnimationState, TrackEntry, spTrackEntry> ⓘ
pub fn track_at_index( &self, index: usize ) -> Option<CTmpRef<'_, Self, TrackEntry>>
pub fn track_at_index_mut( &mut self, index: usize ) -> Option<CTmpMut<'_, Self, TrackEntry>>
sourcepub fn timescale(&self) -> f32
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.
sourcepub fn set_timescale(&mut self, value: f32)
pub fn set_timescale(&mut self, value: f32)
Set the timescale, see timescale
.
pub fn renderer_object(&self) -> RendererObject<'_>
pub fn dispose_statics()
sourcepub const fn c_ptr(&self) -> *mut spAnimationState
pub const fn c_ptr(&self) -> *mut spAnimationState
Get a pointer to the underlying spine-c
type.