pub struct Animation { /* private fields */ }
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 Animations can be combined using a simple state machine.

Implementations

Creates a new looping animation.

Creates a new animation that does not repeat once all of the frames have been displayed.

Draws the current frame to the screen (or to a canvas, if one is enabled).

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.

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.

Restarts the animation from the first frame.

Returns a reference to the texture currently being used by the animation.

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.

Gets the sections of the texture being displayed for each frame of the animation.

Sets the sections of the texture being displayed for each frame of the animation.

This method will reset the animation back to frame zero.

Gets the amount of time that each frame of the animation lasts for.

Sets the amount of time that each frame of the animation lasts for.

Gets whether or not the animation is currently set to repeat when it reaches the end of the frames.

Sets whether or not the animation should repeat when it reaches the end of the frames.

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.

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.

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.

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.