pub struct SpriteSheetAnimator {
pub columns: usize,
pub rows: usize,
pub total_frames: usize,
pub current_frame: usize,
pub fps: f32,
pub looping: bool,
pub playing: bool,
/* private fields */
}Expand description
Sprite sheet (texture atlas) animator.
Steps through frames of a regular grid of sprites in a texture atlas.
Fields§
§columns: usizeNumber of columns in the sprite sheet.
rows: usizeNumber of rows in the sprite sheet.
total_frames: usizeTotal number of frames (may be less than columns * rows if last row is partial).
current_frame: usizeCurrent frame index.
fps: f32Frames per second.
looping: boolWhether to loop.
playing: boolWhether the animation is playing.
Implementations§
Source§impl SpriteSheetAnimator
impl SpriteSheetAnimator
Sourcepub fn with_total_frames(self, total: usize) -> Self
pub fn with_total_frames(self, total: usize) -> Self
Set the total frame count (for partial last rows).
Sourcepub fn with_looping(self, looping: bool) -> Self
pub fn with_looping(self, looping: bool) -> Self
Set looping.
Sourcepub fn current_uv_rect(&self) -> (Vec2, Vec2)
pub fn current_uv_rect(&self) -> (Vec2, Vec2)
Get the UV rect for the current frame: (uv_min, uv_max).
Sourcepub fn frame_uv_rect(&self, frame: usize) -> (Vec2, Vec2)
pub fn frame_uv_rect(&self, frame: usize) -> (Vec2, Vec2)
Get the UV rect for a specific frame.
Sourcepub fn map_uv(&self, local_uv: Vec2) -> Vec2
pub fn map_uv(&self, local_uv: Vec2) -> Vec2
Transform a normalized UV (0-1) to the atlas UV for the current frame.
Sourcepub fn current_cell(&self) -> (usize, usize)
pub fn current_cell(&self) -> (usize, usize)
Get the current frame row and column.
Sourcepub fn is_finished(&self) -> bool
pub fn is_finished(&self) -> bool
Is the animation finished (non-looping only)?
Auto Trait Implementations§
impl Freeze for SpriteSheetAnimator
impl RefUnwindSafe for SpriteSheetAnimator
impl Send for SpriteSheetAnimator
impl Sync for SpriteSheetAnimator
impl Unpin for SpriteSheetAnimator
impl UnsafeUnpin for SpriteSheetAnimator
impl UnwindSafe for SpriteSheetAnimator
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.