Struct omn_sprites::AnimationClip
[−]
[src]
pub struct AnimationClip { pub name: String, pub current_time: Delta, pub direction: Direction, pub duration: Delta, pub drained: bool, // some fields omitted }
AnimationClip
is a group of cell indexes paired with durations such that it can track
playback progress over time. It answers the question of "what subsection of a sprite sheet
should I render at this time?"
It is unusual to construct these yourself. Normally, AnimationClip
instances will be
created by a ClipStore
instance via ClipStore::create()
.
Examples
use omn_sprites::{AnimationClip, CellInfo, Delta, Frame, Region, Direction, PlayMode}; let frames = vec![ Frame { duration: 1000, bbox: Region { x: 0, y: 0, width: 32, height: 32 } }, Frame { duration: 1000, bbox: Region { x: 32, y: 0, width: 32, height: 32 } }, ]; let mut clip = AnimationClip::from_frames("Two Frames", Direction::Forward, PlayMode::Loop, &frames); assert_eq!(clip.get_cell(), Some(0)); clip.update(800.); assert_eq!(clip.get_cell(), Some(0)); clip.update(800.); // as playback progresses, we get different frames as a return assert_eq!(clip.get_cell(), Some(1)); clip.update(800.); // and as the "play head" extends beyond the total duration of the clip, it'll loop back // around to the start. This wrapping behaviour can be customized via the `Direction` parameter. assert_eq!(clip.get_cell(), Some(0));
Fields
name: String
current_time: Delta
direction: Direction
duration: Delta
drained: bool
Methods
impl AnimationClip
[src]
fn new(template: &AnimationClipTemplate, play_mode: PlayMode) -> Self
fn from_frames(
name: &str,
direction: Direction,
play_mode: PlayMode,
frames: &[Frame]
) -> Self
name: &str,
direction: Direction,
play_mode: PlayMode,
frames: &[Frame]
) -> Self
fn update(&mut self, dt: Delta)
fn set_time(&mut self, time: Delta)
Explicitly sets the current time of the clip and adjusts the internal
AnimationClip.drained
value based on the clip's mode and whether the new time is larger
than the duration.
fn reset(&mut self)
Put the play head back to the start of the clip.
fn get_cell(&self) -> Option<usize>
Returns the cell index for the current time of the clip or None if the clip is over.
Trait Implementations
impl Debug for AnimationClip
[src]
impl Clone for AnimationClip
[src]
fn clone(&self) -> AnimationClip
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more