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

Methods

impl AnimationClip
[src]

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.

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

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]

Formats the value using the given formatter.

impl Clone for AnimationClip
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more