pub struct Animation { /* private fields */ }
Expand description
Definition of an animation
Deserialization format
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
sourceimpl Animation
impl Animation
sourcepub fn from_frames(frames: impl IntoIterator<Item = Frame>) -> Self
pub fn from_frames(frames: impl IntoIterator<Item = Frame>) -> Self
Create a new animation from frames
sourcepub fn from_indices(
indices: impl IntoIterator<Item = usize>,
frame_rate: FrameRate
) -> Self
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
sourcepub fn repeat_from(self, frame_index: usize) -> Self
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)
Trait Implementations
sourceimpl<'de> Deserialize<'de> for Animation
impl<'de> Deserialize<'de> for Animation
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl Extend<Frame> for Animation
impl Extend<Frame> for Animation
sourcefn extend<T: IntoIterator<Item = Frame>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = Frame>>(&mut self, iter: T)
Extends a collection with the contents of an iterator. Read more
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Extends a collection with exactly one element.
sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
sourceimpl FromIterator<Frame> for Animation
impl FromIterator<Frame> for Animation
sourcefn from_iter<T: IntoIterator<Item = Frame>>(iter: T) -> Self
fn from_iter<T: IntoIterator<Item = Frame>>(iter: T) -> Self
Creates a value from an iterator. Read more
impl Eq for Animation
impl StructuralEq for Animation
impl StructuralPartialEq for Animation
Auto Trait Implementations
impl RefUnwindSafe for Animation
impl Send for Animation
impl Sync for Animation
impl Unpin for Animation
impl UnwindSafe for Animation
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more