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:
frame_duration: 100
frames: [0, 1, 2] # sequence of frame indices
Implementations
sourceimpl Animation
impl Animation
sourcepub fn from_frames(frames: Vec<Frame>) -> Self
pub fn from_frames(frames: Vec<Frame>) -> Self
Create a new animation from frames
sourcepub fn from_range(
index_range: RangeInclusive<usize>,
frame_duration: Duration
) -> Self
pub fn from_range(
index_range: RangeInclusive<usize>,
frame_duration: Duration
) -> Self
Create a new animation from index-range, using the same frame duration for each frame.
For more granular configuration, see from_frames
Panics
Panics if the duration is zero
sourcepub fn from_iter(
indices: impl IntoIterator<Item = usize>,
frame_duration: Duration
) -> Self
pub fn from_iter(
indices: impl IntoIterator<Item = usize>,
frame_duration: Duration
) -> Self
Create a new animation from an index iterator, using the same frame duration for each frame.
Example
You may use this to create a reversed animation:
let animation = Animation::from_iter((0..5).rev(), Duration::from_millis(100));
For more granular configuration, 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 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
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