pub struct SpriteClip { /* private fields */ }Implementations§
Source§impl SpriteClip
impl SpriteClip
pub fn new(frames: Vec<SpriteFrame>) -> Result<SpriteClip, AnimationError>
Sourcepub fn validate_frames(
frames: &[SpriteFrame],
) -> Result<f32, AnimationDiagnostic>
pub fn validate_frames( frames: &[SpriteFrame], ) -> Result<f32, AnimationDiagnostic>
Check borrowed frames and return their accumulated duration, without allocating or consuming the authoring data.
Reports the first frame with a nonfinite/nonpositive duration or whose
addition overflows or fails to advance the accumulated f32 end time.
All such cases have category InvalidKey; empty input has category
Empty and no index. Frame indices may repeat and need not be ordered.
Work is O(frames.len()) with constant scratch space.
use ferravex_play::animation::{SpriteClip, SpriteFrame};
let frames = [
SpriteFrame { index: 7, duration: 0.25 },
SpriteFrame { index: 2, duration: 0.75 },
];
assert_eq!(SpriteClip::validate_frames(&frames), Ok(1.0));
let clip = SpriteClip::new(frames.to_vec()).unwrap();
assert_eq!(clip.frames(), &frames);Sourcepub fn frames(&self) -> &[SpriteFrame]
pub fn frames(&self) -> &[SpriteFrame]
Borrow the original frame indices and durations in playback order.
See Self::validate_frames for an inspection example.
pub fn duration(&self) -> f32
pub fn frame(&self, time: f32, mode: LoopMode) -> Result<u32, AnimationError>
Sourcepub fn sample_into(
&self,
times: &[f32],
mode: LoopMode,
out: &mut [u32],
) -> Result<usize, AnimationError>
pub fn sample_into( &self, times: &[f32], mode: LoopMode, out: &mut [u32], ) -> Result<usize, AnimationError>
Sample sprite indices into a reusable output prefix without allocating.
Returns times.len(), leaving the output tail untouched. Empty input
succeeds. A short output returns Capacity before nonfinite times are
checked (InvalidTime); either error leaves output unchanged. Times may
be negative or unsorted. Each result is identical to Self::frame,
including exact frame/loop boundaries. Work is
O(times.len() * log(frames.len())) with constant scratch space.
use ferravex_play::animation::{LoopMode, SpriteClip, SpriteFrame};
let clip = SpriteClip::new(vec![
SpriteFrame { index: 4, duration: 0.25 },
SpriteFrame { index: 7, duration: 0.75 },
]).unwrap();
let mut out = [99; 4];
assert_eq!(clip.sample_into(&[0.0, 0.25, 1.0], LoopMode::Repeat, &mut out), Ok(3));
assert_eq!(out, [4, 7, 4, 99]);Trait Implementations§
Source§impl Clone for SpriteClip
impl Clone for SpriteClip
Source§fn clone(&self) -> SpriteClip
fn clone(&self) -> SpriteClip
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more