Struct tetra::graphics::animation::Animation [−][src]
pub struct Animation { /* fields omitted */ }
Expand description
An animation, cycling between regions of a texture at a regular interval.
Calling advance
or advance
within State::draw
will drive the animation, switching the texture region once the specified
time has passed.
Examples
The animation
example demonstrates basic usage of an Animation
with a spritesheet.
The animation_controller
example demonstrates how multiple Animation
s can be combined using a
simple state machine.
Implementations
impl Animation
[src]
impl Animation
[src]pub fn new(
texture: Texture,
frames: Vec<Rectangle>,
frame_length: Duration
) -> Animation
[src]
pub fn new(
texture: Texture,
frames: Vec<Rectangle>,
frame_length: Duration
) -> Animation
[src]Creates a new looping animation.
pub fn once(
texture: Texture,
frames: Vec<Rectangle>,
frame_length: Duration
) -> Animation
[src]
pub fn once(
texture: Texture,
frames: Vec<Rectangle>,
frame_length: Duration
) -> Animation
[src]Creates a new animation that does not repeat once all of the frames have been displayed.
pub fn draw<P>(&self, ctx: &mut Context, params: P) where
P: Into<DrawParams>,
[src]
pub fn draw<P>(&self, ctx: &mut Context, params: P) where
P: Into<DrawParams>,
[src]Draws the current frame to the screen (or to a canvas, if one is enabled).
pub fn advance(&mut self, ctx: &Context)
[src]
pub fn advance(&mut self, ctx: &Context)
[src]Advances the animation’s timer, switching the texture region if required.
This method uses the current delta time to calculate how much time has passed.
pub fn advance_by(&mut self, duration: Duration)
[src]
pub fn advance_by(&mut self, duration: Duration)
[src]Advances the animation’s timer by a specified amount, switching the texture region if required.
If the specified duration is longer than the frame length, frames will be skipped.
pub fn texture(&self) -> &Texture
[src]
pub fn texture(&self) -> &Texture
[src]Returns a reference to the texture currently being used by the animation.
pub fn set_texture(&mut self, texture: Texture)
[src]
pub fn set_texture(&mut self, texture: Texture)
[src]Sets the texture that will be used by the animation.
This method will not change the frame definitions or current state of the animation,
so it can be used for e.g. swapping spritesheets. If you need to change the slicing
for the new texture, call set_frames
.
pub fn frames(&self) -> &[Rectangle]
[src]
pub fn frames(&self) -> &[Rectangle]
[src]Gets the sections of the texture being displayed for each frame of the animation.
pub fn set_frames(&mut self, new_frames: Vec<Rectangle>)
[src]
pub fn set_frames(&mut self, new_frames: Vec<Rectangle>)
[src]Sets the sections of the texture being displayed for each frame of the animation.
This method will reset the animation back to frame zero.
pub fn frame_length(&self) -> Duration
[src]
pub fn frame_length(&self) -> Duration
[src]Gets the amount of time that each frame of the animation lasts for.
pub fn set_frame_length(&mut self, new_frame_length: Duration)
[src]
pub fn set_frame_length(&mut self, new_frame_length: Duration)
[src]Sets the amount of time that each frame of the animation lasts for.
pub fn repeating(&self) -> bool
[src]
pub fn repeating(&self) -> bool
[src]Gets whether or not the animation is currently set to repeat when it reaches the end of the frames.
pub fn set_repeating(&mut self, repeating: bool)
[src]
pub fn set_repeating(&mut self, repeating: bool)
[src]Sets whether or not the animation should repeat when it reaches the end of the frames.
pub fn current_frame_index(&self) -> usize
[src]
pub fn current_frame_index(&self) -> usize
[src]Gets the index of the frame that is currently being displayed.
This index is zero-based, and can be used in combination with the frames
method in order to track the progress of the animation.
pub fn set_current_frame_index(&mut self, index: usize)
[src]
pub fn set_current_frame_index(&mut self, index: usize)
[src]Sets which frame of the animation should be displayed.
Usually you will want to control the animation by calling advance
or advance
, but this method can be useful for more
fine-grained control.
Panics
The index is zero-based, and must be within the bounds of the animation’s
frames
, otherwise this method will panic.
pub fn current_frame_time(&self) -> Duration
[src]
pub fn current_frame_time(&self) -> Duration
[src]Gets the duration that the current frame has been visible.
This can be used in combination with the frame_length
method
in order to track the progress of the animation.
pub fn set_current_frame_time(&mut self, duration: Duration)
[src]
pub fn set_current_frame_time(&mut self, duration: Duration)
[src]Sets the duration that the current frame has been visible.
Usually you will want to control the animation by calling advance
or advance
,but this method can be useful for more
fine-grained control.
The animation will not advance past the end of the current frame until the next call
to advance
or advance
. If a value is given
that is larger than frame_length
, this animation may
skip frames.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Animation
impl !Send for Animation
impl !Sync for Animation
impl Unpin for Animation
impl !UnwindSafe for Animation
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn to_owned(&self) -> T
[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)
[src]
pub fn clone_into(&self, target: &mut T)
[src]🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more