Struct AnimationClip

Source
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

Source

pub fn new(template: &AnimationClipTemplate, play_mode: PlayMode) -> Self

Source

pub fn from_frames( name: &str, direction: Direction, play_mode: PlayMode, frames: &[Frame], ) -> Self

Source

pub fn update(&mut self, dt: Delta)

Source

pub 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.

Source

pub fn reset(&mut self)

Put the play head back to the start of the clip.

Source

pub 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§

Source§

impl Clone for AnimationClip

Source§

fn clone(&self) -> AnimationClip

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AnimationClip

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.