pub struct AnimationClip {
pub name: String,
pub current_time: Delta,
pub direction: Direction,
pub duration: Delta,
pub drained: bool,
/* private fields */
}
Expand description
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
Implementations§
Source§impl AnimationClip
impl AnimationClip
pub fn new(template: &AnimationClipTemplate, play_mode: PlayMode) -> Self
pub fn from_frames( name: &str, direction: Direction, play_mode: PlayMode, frames: &[Frame], ) -> Self
pub fn update(&mut self, dt: Delta)
Trait Implementations§
Source§impl Clone for AnimationClip
impl Clone for AnimationClip
Source§fn clone(&self) -> AnimationClip
fn clone(&self) -> AnimationClip
Returns a copy 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 moreAuto Trait Implementations§
impl Freeze for AnimationClip
impl RefUnwindSafe for AnimationClip
impl Send for AnimationClip
impl Sync for AnimationClip
impl Unpin for AnimationClip
impl UnwindSafe for AnimationClip
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