#game #gamedev #bevy #anmiation

benimator

A sprite sheet animation plugin for Bevy

24 releases (stable)

Uses new Rust 2021

new 3.6.1 Jul 2, 2022
3.0.1 May 19, 2022
2.2.0 Mar 6, 2022
1.1.0 Jan 18, 2022
0.3.0 Jul 19, 2021

#111 in Game dev

Download history 141/week @ 2022-03-12 133/week @ 2022-03-19 56/week @ 2022-03-26 51/week @ 2022-04-02 69/week @ 2022-04-09 119/week @ 2022-04-16 89/week @ 2022-04-23 67/week @ 2022-04-30 130/week @ 2022-05-07 307/week @ 2022-05-14 122/week @ 2022-05-21 163/week @ 2022-05-28 221/week @ 2022-06-04 63/week @ 2022-06-11 193/week @ 2022-06-18 75/week @ 2022-06-25

577 downloads per month

Unlicense OR MIT

54KB
1K SLoC

Benimator

License Crates.io Docs Bevy tracking Build

A sprite sheet animation plugin for bevy

Features

  • A SpriteSheetAnimation asset
  • Automatic update indices of a TextureAtlasSprite
  • Animation modes: once, repeat and ping_pong
  • An animation is playing if, and only if, a Play component is present in the entity
    • Simply remove/insert the Play component to pause/resume an animation
  • The animation can be defined from an index-range, or an arbitrary list of indices
  • Each frame may have a different duration

Usage

fn main() {
  App::new()
    .add_plugins(DefaultPlugins)
    .add_plugin(AnimationPlugin::default()) // <-- Add the plugin
    .add_startup_system(spawn)
    .run();
}

fn spawn(
  mut commands: Commands,
  asset_server: Res<AssetServer>,
  mut textures: ResMut<Assets<TextureAtlas>>,
  mut animations: ResMut<Assets<SpriteSheetAnimation>>,
) {
  // Don't forget the camera ;-)
  commands.spawn_bundle(OrthographicCameraBundle::new_2d());

  // Create an animation
  // Here we use an index-range (from 0 to 4) where each frame has the same duration
  let animation_handle = animations.add(SpriteSheetAnimation::from_range(
    0..=4,
    Duration::from_millis(100),
  ));

  commands
          // Spawn a bevy sprite-sheet
          .spawn_bundle(SpriteSheetBundle {
            texture_atlas: textures.add(TextureAtlas::from_grid(asset_server.load("coin.png"), Vec2::new(16.0, 16.0), 5, 1)),
            transform: Transform::from_scale(Vec3::splat(10.0)),
            ..Default::default()
          })
          // Insert the asset handle of the animation
          .insert(animation_handle)
          // Start the animation immediately. Remove this component in order to pause the animation.
          .insert(Play);
}

Here is the result:

Example result

(Asset by La Red Games - CC0)

For more details see the documentation

Installation

Add the dependency to your project

cargo add benimator

Cargo features

  • yaml deserialization from yaml asset files (also requires unstable-load-from-file)
  • ron deserialization from ron asset files (also requires unstable-load-from-file)

Unstable features

Any API behind one of theses feature flags is unstable, should not be considered complete nor part of the public API. Breaking changes to that API may happen in minor releases

  • unstable-load-from-file Load animation assets from yaml/ron files. It also requires either ron or yaml (or both) features.

MSRV

The minimum supported rust version is currently: 1.60

It may be increased to a newer stable version in a minor release. (but only if needed)

It will be increased to the latest stable version in a major release. (even if not needed)

Bevy Version Compatibility

bevy benimator
0.7 3
0.6 1, 2
0.5 0.1 - 0.3

Note: Only the latest published version of benimator is supported

Contribute / Contact

Discussions, issues and pull requests are welcome.

It is possible to directly discuss with me (Jomag#2675) via the bevy discord

License

Licensed under either of

at your option.

Dependencies

~22MB
~459K SLoC