pub struct AnimationDriver { /* private fields */ }Expand description
Manages a collection of animations, ticking them each frame and automatically removing completed ones.
§Example
use animato_driver::{AnimationDriver, MockClock, Clock};
use animato_tween::Tween;
use animato_core::Easing;
let mut driver = AnimationDriver::new();
let id = driver.add(
Tween::new(0.0_f32, 1.0).duration(1.0).build()
);
assert!(driver.is_active(id));
assert_eq!(driver.active_count(), 1);
// Tick past completion:
driver.tick(2.0);
assert!(!driver.is_active(id));
assert_eq!(driver.active_count(), 0);Implementations§
Source§impl AnimationDriver
impl AnimationDriver
Sourcepub fn add<A: Update + Send + 'static>(&mut self, anim: A) -> AnimationId
pub fn add<A: Update + Send + 'static>(&mut self, anim: A) -> AnimationId
Register an animation and return its AnimationId.
The animation will be ticked on every call to tick
and automatically removed when it returns false from update.
Sourcepub fn add_recorded<A, F>(
&mut self,
label: impl Into<String>,
anim: A,
sampler: F,
) -> AnimationId
pub fn add_recorded<A, F>( &mut self, label: impl Into<String>, anim: A, sampler: F, ) -> AnimationId
Register an animation with a scalar sampler for tick_recorded.
Sourcepub fn tick(&mut self, dt: f32)
pub fn tick(&mut self, dt: f32)
Advance all active animations by dt seconds.
Animations that return false from update are marked and removed
at the end of the tick — no allocation during the tick itself.
Sourcepub fn tick_recorded(
&mut self,
dt: f32,
time: f32,
recorder: &mut AnimationRecorder,
)
pub fn tick_recorded( &mut self, dt: f32, time: f32, recorder: &mut AnimationRecorder, )
Advance all active animations and record sampled values after the tick.
Sourcepub fn cancel(&mut self, id: AnimationId)
pub fn cancel(&mut self, id: AnimationId)
Cancel an animation by id.
The animation is removed immediately, before the next tick. No-op if the id is not found (e.g. already completed).
Sourcepub fn cancel_all(&mut self)
pub fn cancel_all(&mut self)
Cancel all active animations.
Sourcepub fn active_count(&self) -> usize
pub fn active_count(&self) -> usize
Number of currently active animations.
Sourcepub fn is_active(&self, id: AnimationId) -> bool
pub fn is_active(&self, id: AnimationId) -> bool
true if the animation with the given id is still active.