Crate benimator[−][src]
Expand description
A sprite-sheet animation plugin for bevy
Usage
- Add the
AnimationPlugin
plugin
use std::time::Duration; use bevy::prelude::*; use benimator::*; fn main() { App::build() .add_plugins(DefaultPlugins) .add_plugin(AnimationPlugin) // <-- Enable sprite-sheet animations .add_startup_system(spawn.system()) // ... .run() } fn spawn() { /* ... */ }
- Insert the
SpriteSheetAnimation
component to the sprite sheets you want to animate
fn spawn(mut commands: Commands) { commands .spawn_bundle(SpriteSheetBundle { // TODO: Configure the sprite sheet ..Default::default() }) // Insert the animation component .insert(SpriteSheetAnimation::from_range( 0..=2, // Indices of the sprite atlas Duration::from_secs_f64(1.0 / 12.0), // Duration of each frame )) // Start the animation immediately .insert(Play); }
Run the animation only once
By default the animation loops forever. But it is possible to configure it differently:
commands .spawn_bundle(SpriteSheetBundle { ..Default::default() }) .insert( SpriteSheetAnimation::from_range(0..=2, Duration::from_millis(100)) .once() // <-- Runs the animation only once ) .insert(Play); // <-- This component will be automatically removed once the animation is finished
Play/Pause
Animations proceed only if the Play
component is in the entity.
To pause or resume an animation, simply remove/insert the Play
component.
Fine-grained frame-duration
For more precise configuration, it is possible to define the duration of each frame:
SpriteSheetAnimation::from_frames(vec![ Frame::new(0, Duration::from_millis(120)), Frame::new(1, Duration::from_millis(100)), Frame::new(2, Duration::from_millis(80)), ]);
Structs
Plugin to enable sprite-sheet animation
A single animation frame
Components that indicates the animation is playing
Component to animate the TextureAtlasSprite
of the same entity
Enums
Animation mode (run once or repeat)
Labels of systems that run during the post-update stage