Struct benimator::Animation

source ·
pub struct Animation { /* private fields */ }
Expand description

Definition of an animation

Deserialization format

# The mode can be one of: 'Once', 'Repeat', 'PingPong'
# or '!RepeatFrom: n' (where 'n' is the frame-index to repeat from)
# The default is 'Repeat'
mode: PingPong
frames:
  - index: 0 # index in the sprite sheet for that frame
    duration: 100 # duration of the frame in milliseconds
  - index: 1
    duration: 100
  - index: 2
    duration: 120

There is also a short-hand notation if all frames have the same duration:

fps: 12 # may be substitued by 'frame_duration' of 'total_duration'
frames: [0, 1, 2] # sequence of frame indices

Implementations§

source§

impl Animation

source

pub fn from_frames(frames: impl IntoIterator<Item = Frame>) -> Self

Create a new animation from frames

source

pub fn from_indices( indices: impl IntoIterator<Item = usize>, frame_rate: FrameRate ) -> Self

Create a new animation from an index iterator, using the same frame duration for each frame.

Examples
// From an index range
let animation = Animation::from_indices(0..=5, FrameRate::from_fps(12.0));

// From an index array
let animation = Animation::from_indices([1, 2, 3, 4], FrameRate::from_fps(12.0));

// Reversed animation
let animation = Animation::from_indices((0..5).rev(), FrameRate::from_fps(12.0));

// Chained ranges
let animation = Animation::from_indices((0..3).chain(10..15), FrameRate::from_fps(12.0));

Note, the FrameRate may be created from fps, frame-duration and animation-duration

To use different non-uniform frame-duration, see from_frames

Panics

Panics if the duration is zero

source

pub fn once(self) -> Self

Runs the animation once and then stop playing

source

pub fn repeat(self) -> Self

Repeat the animation forever

source

pub fn repeat_from(self, frame_index: usize) -> Self

Repeat the animation forever, from a given frame index (loop back to it at the end of the animation)

source

pub fn ping_pong(self) -> Self

Repeat the animation forever, going back and forth between the first and last frame.

Trait Implementations§

source§

impl Clone for Animation

source§

fn clone(&self) -> Animation

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 Animation

source§

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

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for Animation

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Extend<Frame> for Animation

source§

fn extend<T: IntoIterator<Item = Frame>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl FromIterator<Frame> for Animation

source§

fn from_iter<T: IntoIterator<Item = Frame>>(iter: T) -> Self

Creates a value from an iterator. Read more
source§

impl PartialEq<Animation> for Animation

source§

fn eq(&self, other: &Animation) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Animation

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Eq for Animation

source§

impl StructuralEq for Animation

source§

impl StructuralPartialEq for Animation

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,