bevy_spritesheet_animation is a Bevy plugin for easily animating 2D and 3D sprites.
![]()
[!TIP] This crate supports the latest Bevy 0.17. Please check the compatibility table to see which versions of this crate work with older Bevy versions.
[!NOTE] This crate is under active development. Please regularly check the CHANGELOG for recent changes.
Features
- Animate 2D sprites, 3D sprites, UI images and cursors! 🎉
- Easily build animations from spritesheets with custom parameters like duration, repetitions, direction and easing.
- Trigger events when animations end or reach specific points.
Quick start
- Add the SpritesheetAnimationPlugin to your app
- Build animations with the Spritesheet API
- Add SpritesheetAnimation components to your entities
use *;
use *;
Overview
Animations
In its simplest form, an Animation is a sequence of cells extracted from a spritesheet image.
Use a Spritesheet to create an Animation.
For each animation, you can control its duration, repetitions, direction and easing.
// Here, we extract two animations from an 8x8 spritesheet image
let image = assets.load;
let spritesheet = new
// Let's create a looping animation from the first row
let run_animation = spritesheet
.create_animation
.add_row
.set_duration
.set_repetitions
.build;
// Let's create another animation from another row, with different playback parameters
let shoot_animation = spritesheet
.create_animation
.add_row
.set_duration
.set_easing
.build;
Clips
To create more sophisticated animations, you can leverage a lower-level construct: clips.
Think of clips as sub-animations that are chained together and have their own parameters (duration, repetitions, etc...).
let animation = new
.create_animation
// An animation starts with an implicit clip that you can edit right away
//
// Parameters set with set_clip_xxx() only apply to the current clip
.add_row
.set_clip_duration
// Call start_clip() to add another clip
//
// Here the second clip uses the same frames but will play faster and repeat a few times
.start_clip
.add_row
.set_clip_duration
.set_clip_repetitions
// Parameters set with set_xxx() apply to the whole animation
.set_direction
.build;
Animations are assets
Just like Bevy's images, materials or meshes, this crate's animations are assets.
After creating an animation, register it in Assets<Animation>.
This will give you a Handle<Animation> that you can assign to SpritesheetAnimation components.
[!WARNING] An animation should be created only once and then assigned to as many sprites as you need. Creating identical animations gives more work to the plugin and may degrade performance.
Interaction with Bevy's built-in components
To animate an entity, you just have to give it:
- a regular Sprite component (provided by Bevy)
- a SpritesheetAnimation component (provided by this crate)
This crate provides a few helpers to make the creation of such entities more concise.
In the simplest case, you can use sprite() to get an animation-ready sprite with the correct image and texture atlas:
commands.spawn;
If you need more control, for instance to set some sprite attributes like its color, you might prefer to construct the sprite yourself.
In that case, you can spell out the entity creation and use Spritesheet::atlas() to retrieve the texture atlas that matches your spritesheet.
commands.spawn;
Accessing your animations across systems
If you need to access your animations from different systems, store their handles in custom resources.
This method is showcased in the character and events examples.
3D sprites
![]()
This crate also makes it easy to integrate 3D sprites into your games, which is not supported by Bevy out of the box.
Animating a 3D sprite is the same as animating 2D sprites: simply spawn a Sprite3d instead of Bevy's built-in Sprite and attach a SpritesheetAnimation component to the entity.
Like for 2D sprites, Spritesheet provides a helper that creates an animation-ready 3D sprite:
let sprite3d = spritesheet
.with_size_hint
.sprite3d
.with_color
.with_flip;
commands.spawn;
[!TIP] Static 3D sprites can also be spawned by omitting the
SpritesheetAnimationcomponent.
UI images
![]()
This crate also animates UI images with the same workflow.
Please check out the complete example.
Cursors
![]()
This crate also animates cursors with the same workflow.
Please check out the complete example.
More examples
For more examples, browse the examples/ directory.
| Example | Description |
|---|---|
| basic | Shows how to create a simple animated sprite |
| composition | Shows how to create an animation with multiple clips |
| progress | Shows how to query/control the progress of an animation |
| parameters | Shows the effect of each animation parameter |
| character | Shows how to create a controllable character with multiple animations |
| events | Shows how to handle animation events |
| 3d | Shows how to create 3D sprites |
| cursor | Shows how to create an animated cursor |
| ui | Shows how to create an animated UI image |
| headless | Shows how to run animations in a headless Bevy app without rendering |
| stress | Stress test with thousands of animated sprites (either 2D or 3D) |
Compatibility
| bevy | bevy_spritesheet_animation |
|---|---|
| 0.17 | 4.0.0 |
| 0.16 | 3.0.0 |
| 0.15 | 2.0.0 |
| 0.14 | 0.2.0 |
| 0.13 | 0.1.0 |
Credits
- Assets used in the examples:
- Character spritesheet by thekingphoenix
- Cursor spritesheet by crusenho
- Hearts spritesheet by ELV Games