pub struct Animation {
pub name: String,
pub frame_size: Vec2,
pub frames: Vec<AnimationFrame>,
pub speed: f32,
pub looping: bool,
pub ping_pong: bool,
pub offset: Vec2,
}Expand description
A single animation defined from a sprite sheet.
Fields§
§name: StringHuman-readable name (e.g., “idle”, “run”, “attack”).
frame_size: Vec2Region of the sprite sheet: (x, y, width, height) per frame in pixels.
frames: Vec<AnimationFrame>Frames in this animation (indices into the sprite sheet row).
speed: f32Playback speed (1.0 = normal, 2.0 = double speed).
looping: boolWhether to loop.
ping_pong: boolWhether to ping-pong (play forward then backward).
offset: Vec2Offset from the sprite’s position (for attack effects, etc.).
Implementations§
Source§impl Animation
impl Animation
Sourcepub fn from_row(
name: &str,
row: u32,
start_col: u32,
end_col: u32,
frame_duration: f32,
) -> Self
pub fn from_row( name: &str, row: u32, start_col: u32, end_col: u32, frame_duration: f32, ) -> Self
Create a simple animation with evenly-spaced frames in a single row.
name— animation namerow— sprite sheet rowstart_col— first column (inclusive)end_col— last column (inclusive)frame_duration— seconds per frame
Sourcepub fn with_frame_size(self, w: f32, h: f32) -> Self
pub fn with_frame_size(self, w: f32, h: f32) -> Self
Builder: set frame size.
Sourcepub fn with_speed(self, speed: f32) -> Self
pub fn with_speed(self, speed: f32) -> Self
Builder: set speed.
Sourcepub fn with_looping(self, looping: bool) -> Self
pub fn with_looping(self, looping: bool) -> Self
Builder: set looping.
Sourcepub fn with_ping_pong(self) -> Self
pub fn with_ping_pong(self) -> Self
Builder: set ping-pong.
Sourcepub fn with_offset(self, x: f32, y: f32) -> Self
pub fn with_offset(self, x: f32, y: f32) -> Self
Builder: set offset.
Sourcepub fn with_frame_event(self, frame_index: usize, event: &str) -> Self
pub fn with_frame_event(self, frame_index: usize, event: &str) -> Self
Add an event to a specific frame.
Sourcepub fn total_duration(&self) -> f32
pub fn total_duration(&self) -> f32
Total duration of the animation in seconds.
Sourcepub fn frame_count(&self) -> usize
pub fn frame_count(&self) -> usize
Number of frames.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Animation
impl RefUnwindSafe for Animation
impl Send for Animation
impl Sync for Animation
impl Unpin for Animation
impl UnsafeUnpin for Animation
impl UnwindSafe for Animation
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