pub struct Animator {
pub current_animation: Option<SpriteAnimation>,
pub current_frame_index: usize,
pub elapsed_time: f64,
pub state: AnimationState,
pub direction: i32,
pub flip_y: bool,
/* private fields */
}Expand description
Manages the playback state of sprite animations.
Fields§
§current_animation: Option<SpriteAnimation>The currently active animation, if any.
get_current_animation is public: engine/tests/animator inspects the
active clip from outside this crate. get_mut / set stay
crate-internal — clip changes go through the playback API.
current_frame_index: usizeThe index of the current frame being displayed.
elapsed_time: f64The elapsed time within the current frame, in seconds.
state: AnimationStateThe current playback state.
direction: i32The direction of playback (1 = forward, -1 = backward) for ping-pong mode.
flip_y: boolWhether to flip the sprite vertically when rendering.
Implementations§
Source§impl Animator
Implements playback control for Animator.
impl Animator
Implements playback control for Animator.
Sourcepub fn play(&mut self, animation: SpriteAnimation)
pub fn play(&mut self, animation: SpriteAnimation)
Sourcepub fn update(&mut self, delta_time: f64)
pub fn update(&mut self, delta_time: f64)
Advances the animation by the given delta time.
§Arguments
f64- The time elapsed since the last update, in seconds.
Sourcepub fn current_frame_source(&self) -> Option<Rect>
pub fn current_frame_source(&self) -> Option<Rect>
Returns the source rectangle of the current frame, or None if no animation is playing.
§Returns
Option<Rect>- The current frame’s source rectangle.
Source§impl Animator
Implements animated sprite rendering for Animator.
impl Animator
Implements animated sprite rendering for Animator.
Sourcepub fn draw(
&self,
context: &CanvasRenderingContext2d,
sheet: &SpriteSheet,
transform: &Transform2D,
)
pub fn draw( &self, context: &CanvasRenderingContext2d, sheet: &SpriteSheet, transform: &Transform2D, )
Draws the current frame of this animator onto the canvas.
§Arguments
&CanvasRenderingContext2d- The canvas context.&SpriteSheet- The sprite sheet containing the image.&Transform2D- The world-space transform to apply.
Source§impl Animator
impl Animator
pub fn get_current_animation(&self) -> Option<SpriteAnimation>
pub fn try_get_current_animation(&self) -> Option<SpriteAnimation>
pub fn get_current_frame_index(&self) -> usize
pub fn get_elapsed_time(&self) -> f64
pub fn get_state(&self) -> AnimationState
pub fn get_direction(&self) -> i32
pub fn get_flip_y(&self) -> bool
Trait Implementations§
impl StructuralPartialEq for Animator
Source§impl Updatable for Animator
Forwards Animator::update through the Updatable trait so that
collections of heterogeneous updateable objects (entities, animators,
physics worlds, scene managers) can be driven by a single scheduler loop.
impl Updatable for Animator
Forwards Animator::update through the Updatable trait so that
collections of heterogeneous updateable objects (entities, animators,
physics worlds, scene managers) can be driven by a single scheduler loop.
The inherent Animator::update method is the canonical implementation;
this impl exists purely for trait dispatch. The inherent call resolves
first when both are in scope, so there is no recursion.