pub struct SpriteAnimator {
pub animations: HashMap<String, SpriteAnimation>,
pub state_machine: Option<AnimationStateMachine>,
/* private fields */
}Expand description
Drives frame-by-frame sprite animations with an optional state machine.
Fields§
§animations: HashMap<String, SpriteAnimation>§state_machine: Option<AnimationStateMachine>Optional state machine for automatic transitions.
Implementations§
Source§impl SpriteAnimator
impl SpriteAnimator
pub fn new() -> Self
Sourcepub fn add_animation(&mut self, anim: SpriteAnimation)
pub fn add_animation(&mut self, anim: SpriteAnimation)
Add an animation to the library.
Sourcepub fn play_if_different(&mut self, name: &str)
pub fn play_if_different(&mut self, name: &str)
Play only if not already playing this animation (avoids restart).
Sourcepub fn is_finished(&self) -> bool
pub fn is_finished(&self) -> bool
Whether the current animation has finished (Once/OnceAndDone).
Sourcepub fn is_playing(&self) -> bool
pub fn is_playing(&self) -> bool
Whether the animator is currently playing.
Sourcepub fn current_animation(&self) -> &str
pub fn current_animation(&self) -> &str
Current animation name.
Sourcepub fn current_frame_index(&self) -> usize
pub fn current_frame_index(&self) -> usize
Current frame index.
Sourcepub fn current_glyphs(&self) -> &[FrameGlyph]
pub fn current_glyphs(&self) -> &[FrameGlyph]
Get the current frame’s glyphs. Returns empty slice if no animation.
Sourcepub fn current_frame(&self) -> Option<&SpriteFrame>
pub fn current_frame(&self) -> Option<&SpriteFrame>
Get the current SpriteFrame if one exists.
Sourcepub fn drain_events(&mut self) -> Vec<AnimEvent>
pub fn drain_events(&mut self) -> Vec<AnimEvent>
Drain all pending events.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SpriteAnimator
impl RefUnwindSafe for SpriteAnimator
impl Send for SpriteAnimator
impl Sync for SpriteAnimator
impl Unpin for SpriteAnimator
impl UnsafeUnpin for SpriteAnimator
impl UnwindSafe for SpriteAnimator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.