pub struct SpriteAnimator {
pub clip: AnimationClip,
pub current_frame: usize,
pub elapsed: f32,
pub playing: bool,
pub finished: bool,
}Expand description
ECS component that drives sprite sheet animation.
Attach this to an entity alongside a Sprite
to animate the sprite’s source_rect through a sequence of frames.
§Example
use goud_engine::ecs::components::sprite_animator::{SpriteAnimator, AnimationClip};
use goud_engine::core::math::Rect;
let clip = AnimationClip::new(
vec![Rect::new(0.0, 0.0, 32.0, 32.0), Rect::new(32.0, 0.0, 32.0, 32.0)],
0.1,
);
let animator = SpriteAnimator::new(clip);
assert!(animator.playing);
assert!(!animator.finished);Fields§
§clip: AnimationClipThe animation clip driving this animator.
current_frame: usizeIndex of the current frame in clip.frames.
elapsed: f32Accumulated time since the last frame advance.
playing: boolWhether the animation is currently playing.
finished: boolWhether a OneShot animation has completed.
Implementations§
Source§impl SpriteAnimator
impl SpriteAnimator
Sourcepub fn new(clip: AnimationClip) -> SpriteAnimator
pub fn new(clip: AnimationClip) -> SpriteAnimator
Creates a new animator from the given clip, starting playback immediately.
Sourcepub fn is_finished(&self) -> bool
pub fn is_finished(&self) -> bool
Returns true if a OneShot animation has completed.
Sourcepub fn current_rect(&self) -> Option<Rect>
pub fn current_rect(&self) -> Option<Rect>
Returns the source Rect for the current frame, or None if
the clip has no frames.
Trait Implementations§
Source§impl Clone for SpriteAnimator
impl Clone for SpriteAnimator
Source§fn clone(&self) -> SpriteAnimator
fn clone(&self) -> SpriteAnimator
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SpriteAnimator
impl Debug for SpriteAnimator
Source§impl<'de> Deserialize<'de> for SpriteAnimator
impl<'de> Deserialize<'de> for SpriteAnimator
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<SpriteAnimator, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<SpriteAnimator, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl PartialEq for SpriteAnimator
impl PartialEq for SpriteAnimator
Source§impl Serialize for SpriteAnimator
impl Serialize for SpriteAnimator
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl Component for SpriteAnimator
impl StructuralPartialEq for SpriteAnimator
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more