Skip to main content

AnimationPlayer

Struct AnimationPlayer 

Source
pub struct AnimationPlayer { /* private fields */ }
Expand description

An animation player that controls playback of one animation at a time.

§Example

let mut player = AnimationPlayer::new();
player.play(&idle_anim);
player.play(&run_anim);

// In update:
let events = player.update(dt);
for event in events {
    if event == "footstep" { play_sound("step.wav"); }
}

Implementations§

Source§

impl AnimationPlayer

Source

pub fn new() -> Self

Create a new animation player.

Source

pub fn play(&mut self, anim: &Animation)

Start playing an animation.

If restart is true, always restarts from frame 0. If false, only restarts if it’s a different animation.

Source

pub fn restart(&mut self)

Force-restart the current animation.

Source

pub fn pause(&mut self)

Pause the animation.

Source

pub fn resume(&mut self)

Resume from pause.

Source

pub fn stop(&mut self)

Stop and reset.

Source

pub fn current_name(&self) -> Option<&str>

Get the current animation name, if any.

Source

pub fn current_frame_rect(&self) -> Option<(u32, u32, f32, f32)>

Get the current frame’s source rectangle (UV region in the sprite sheet).

Source

pub fn frame_index(&self) -> usize

Get the current frame index.

Source

pub fn state(&self) -> AnimationState

Get the playback state.

Source

pub fn offset(&self) -> Vec2

Get the animation offset.

Source

pub fn update(&mut self, dt: f32) -> &[String]

Update the animation player. Returns events triggered this frame.

Trait Implementations§

Source§

impl Debug for AnimationPlayer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AnimationPlayer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.