pub struct AnimationPlayer { /* private fields */ }Expand description
CPU playback cursor. Drawing/reading a frame never changes playback. Advancement uses integer nanoseconds and binary frame lookup, so large time steps do not iterate over every crossed frame or loop.
Implementations§
Source§impl AnimationPlayer
impl AnimationPlayer
Sourcepub fn new(clip: impl Into<Arc<AnimationClip>>) -> Self
pub fn new(clip: impl Into<Arc<AnimationClip>>) -> Self
Starts at the first frame, unpaused. Accepts an owned clip or shared Arc.
Sourcepub fn play(&mut self, clip: impl Into<Arc<AnimationClip>>)
pub fn play(&mut self, clip: impl Into<Arc<AnimationClip>>)
Switches/restarts a clip, clearing pause and completion state.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Rewinds this clip and rearms its completion event, preserving pause state.
Sourcepub fn resume(&mut self)
pub fn resume(&mut self)
Allows advancement again. A completed one-shot remains completed until reset/play.
Sourcepub fn is_finished(&self) -> bool
pub fn is_finished(&self) -> bool
Whether a one-shot has reached its end.
Sourcepub fn clip(&self) -> &Arc<AnimationClip> ⓘ
pub fn clip(&self) -> &Arc<AnimationClip> ⓘ
Current immutable clip.
Sourcepub fn elapsed(&self) -> Duration
pub fn elapsed(&self) -> Duration
Time within this traversal, clamped to duration for a finished one-shot.
Sourcepub fn frame_index(&self) -> usize
pub fn frame_index(&self) -> usize
Current frame index. Exact boundaries select the next frame; a completed one-shot holds the last frame for drawing.
Sourcepub fn frame(&self) -> &SpriteFrame
pub fn frame(&self) -> &SpriteFrame
Current frame, without advancing simulation.
Sourcepub fn advance(&mut self, dt: Duration) -> Option<AnimationCompleted>
pub fn advance(&mut self, dt: Duration) -> Option<AnimationCompleted>
Advances by explicitly supplied simulation time. Zero time, paused or
completed playback does nothing. Looping wraps including exact boundaries;
a one-shot discards excess time and returns one completion on its first end.
No allocation occurs, including at completion (the clip’s Arc is cloned).