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
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§
source§impl<'de> Deserialize<'de> for Animation
impl<'de> Deserialize<'de> for Animation
source§fn 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
source§impl Extend<Frame> for Animation
impl Extend<Frame> for Animation
source§fn 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
source§fn extend_one(&mut self, item: A)
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)
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
impl FromIterator<Frame> for Animation
source§impl PartialEq<Animation> for Animation
impl PartialEq<Animation> for Animation
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§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more