A sprite-sheet animation plugin for bevy

Overview

Benimator

License Crates.io Docs Bevy tracking dependency status Build

A sprite sheet animation plugin for bevy

Features

  • A SpriteSheetAnimation component to automatically update the indices of the TextureAtlasSprite in the same entity
  • Animation modes: Repeat or Once
  • 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::build()
          .add_plugins(DefaultPlugins)
          .add_plugin(AnimationPlugin) // <-- Add the plugin
          .add_startup_system(spawn.system())
          .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 to Cargo.toml:

benimator = "0.3.1"

Cargo features

  • warnings (enabled by default). Log warnings in case of incorrect usage detected.

Bevy Version Compatibility

bevy benimator
0.5 >= 0.1

Contribute / Contact

Issues, 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.

Comments
  • How to execute logic when the animation reaches a specific frame?

    How to execute logic when the animation reaches a specific frame?

    I'm currently trying to trigger some logic at a specific frame of the animation, but it seems SpriteSheetAnimationState::current_frame isn't public, is there are reason for that? Also I think a more powerful system which automatically sends events for tagged frames (which you would tag when constructing the animation), would be very helpful for many cases.

    enhancement design 
    opened by XBagon 14
  • Load SpriteSheetAnimation from a file

    Load SpriteSheetAnimation from a file

    Any chance to get support for loading a SpriteSheetAnimation from a file (behind a feature flag)? For example, one could load them from .ron.animation files.

    enhancement design released 
    opened by NiklasEi 7
  • Stabilize: load-from-file

    Stabilize: load-from-file

    The cargo feature unstable-load-from-file allows loading animation from YAML or RON files.

    Eventually, this should be stabilized. The present issue is there to track what needs to be considered/done before stabilizing the feature.

    It is also open to gathering comments and thoughts about the current state of the API.

    Tasks

    • [x] fix crash when one frame duration is zero
    • [x] make it easier to write an animation file when all frames have the same duration
    • [x] configure documentation so that the new API shows up on docs.rs
    • [x] ron support
    • [x] gate yaml and ron behind feature flags (in addition of the load-from-file gate)
    • [x] document shorthand notation for ron
    • [x] implicit_some for ron
    • [x] remove public functions from_(yaml|ron)_(str|bytes).
      • Having a public implementation or serde::Deserialize is enough to let the user choose the format and library of their choice. Not to mention that most users would not use it directly anyway as they would use the asset loader instead.

    Open questions

    • [x] is yaml a good choice?
      • I think it is. However, I am okay to support additional formats (such as ron) and let the user choose what they prefer.
    • [x] is the extension .animation.(yaml|yml|ron) a good choice?
      • I think it is not bad. Ultimately if it turns out to be problematic later, it would be possible to let the user choose the extension (without breaking the API)
    • [x] is the schema sensible? Clearly understood/documented?
      • I think it is not too bad. Not to say it is perfect, but I think it doesn't block the stabilization of the feature. We may still improve it later without breaking the API.
    opened by jcornaz 5
  • Play backward

    Play backward

    As suggested in bevy discord: https://discord.com/channels/691052431525675048/691052431974465548/928336941643075606

    Potential API

    Right now I am leaning toward a flag in the animation state component. So that it is possible to change the direction without changing the animation resource.

    enhancement up-for-grabs 
    opened by jcornaz 5
  • fix: delayed animation start when switching to a new animation

    fix: delayed animation start when switching to a new animation

    The SpriteSheetAnimationState update function doesn't always update the sprite index to match the current frame index. When changing animations, this delays update of sprite.index until after the first frame duration has elapsed.

    To fix this, always update the sprite index to match the current frame.

    bug released 
    opened by edwardvear 4
  • feat: create ping pong animation mode

    feat: create ping pong animation mode

    Allows the creation of animations using the PingPong mode. This is a WIP solution, there may be alternative implementations.

    A possible implementation would be to insert state into the PingPong mode, so that users of the Repeat and Once AnimationMode's would not pay in storage for the PingPong logic.

    The problem with this approach is that users would either:

    • See the internal logic inside the PingPong mode
    • Not be able to construct PingPong directly (AnimationMode fields are made private to improve API).

    Closes #11

    opened by aaneto 4
  • feat: play animation with custom playback speed

    feat: play animation with custom playback speed

    closes #65

    This PR implements a new component, called PlaySpeedMultiplier(f64) that can be applied to entities so as to multiply the animation's playback rate.

    Example usage

        // Edit Hero entity
        commands
            ...
            ...
            ...
            // Play walk cycle animation
            .insert(Play)
            // Double the playback speed since we are walking in special terrain
            .insert(PlaySpeedMultiplier::new(2.0))
    
    
    enhancement released 
    opened by flipbit03 3
  • chore(deps): update rust crate yaml to 0.8.25

    chore(deps): update rust crate yaml to 0.8.25

    Mend Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | yaml | dependencies | patch | 0.8.24 -> 0.8.25 |


    Release Notes

    dtolnay/serde-yaml

    v0.8.25

    Compare Source

    • Add to "encoding" category on crates.io (#​246)

    Configuration

    πŸ“… Schedule: Branch creation - "every weekend" (UTC), Automerge - At any time (no schedule defined).

    🚦 Automerge: Enabled.

    β™» Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    πŸ”• Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, click this checkbox.

    This PR has been generated by Mend Renovate. View repository job log here.

    released released on @alpha 
    opened by renovate[bot] 2
  • chore(deps): update rust crate criterion to 0.3.6

    chore(deps): update rust crate criterion to 0.3.6

    Mend Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | criterion (source) | dev-dependencies | patch | 0.3.5 -> 0.3.6 |


    Release Notes

    bheisler/criterion.rs

    v0.3.6

    Compare Source

    Changed
    • MSRV bumped to 1.49
    • Symbol for microseconds changed from ASCII 'us' to unicode 'Β΅s'
    • Documentation fixes
    • Clippy fixes

    Configuration

    πŸ“… Schedule: Branch creation - "every weekend" (UTC), Automerge - At any time (no schedule defined).

    🚦 Automerge: Enabled.

    β™» Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    πŸ”• Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, click this checkbox.

    This PR has been generated by Mend Renovate. View repository job log here.

    released released on @alpha 
    opened by renovate[bot] 2
  • chore(deps): update rust crate rstest to 0.15.0

    chore(deps): update rust crate rstest to 0.15.0

    Mend Renovate

    This PR contains the following updates:

    | Package | Type | Update | Change | |---|---|---|---| | rstest | dev-dependencies | minor | 0.14.0 -> 0.15.0 |


    Release Notes

    la10736/rstest

    v0.15.0

    Compare Source

    Fixed
    • Timeout not compile if one of its test arguments il not a copy type [see #​154]

    Configuration

    πŸ“… Schedule: Branch creation - "every weekend" (UTC), Automerge - At any time (no schedule defined).

    🚦 Automerge: Enabled.

    β™» Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

    πŸ”• Ignore: Close this PR and you won't be reminded about this update again.


    • [ ] If you want to rebase/retry this PR, click this checkbox.

    This PR has been generated by Mend Renovate. View repository job log here.

    released released on @alpha 
    opened by renovate[bot] 2
  • Implement custom playback rates

    Implement custom playback rates

    I have an use case where I am extracting animation data from .aseprite files using bevy_ase. The process is very smooth and a nice thing is that, using the benimator feature of that crate, I am able to transform the extracted animation tags (frame ranges) into SpriteSheetAnimation objects which I can attach to my entities and use normally. That unexpected integration between the projects saved a lot of time on my end in that I don't have to reinvent an animation system from scratch :+1: :raised_hands: :heart:

    The problem is, I cannot dynamically alter the playback speed of the extracted animations, which would be useful in my project, as the hero can walk in different terrains and I'd like to speed up/slow down its walk cycle :runner: without resorting to recreating the animation frames from scratch :dizzy_face:

    My idea is for us to have an additional optional component that, when applied, will reach benimator's internal "update animation" system, altering the behavior of the update() function to take into consideration said multiplier :robot: :runner:

    enhancement released 
    opened by flipbit03 2
  • Dependency Dashboard

    Dependency Dashboard

    This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

    This repository currently has no open or pending branches.

    Detected dependencies

    cargo
    Cargo.toml
    • serde 1.0
    • serde_yaml 0.9.16
    • rstest 0.16.0
    • bevy 0.9.1
    • anyhow 1.0
    • rustc_version 0.4.0
    github-actions
    .github/workflows/look-ahead.yml
    • actions/checkout v3
    • actions-rs/toolchain v1.0.7
    .github/workflows/release.yml
    • actions/checkout v3
    • actions-rs/toolchain v1
    • extractions/setup-just v1
    .github/workflows/verify.yml
    • actions/checkout v3
    • actions-rs/toolchain v1
    • Swatinem/rust-cache v2
    • extractions/setup-just v1

    • [ ] Check this box to trigger a request for Renovate to run again on this repository
    opened by renovate[bot] 0
Releases(v4.1.0)
  • v4.1.0(Oct 11, 2022)

  • v4.0.0(Sep 1, 2022)

    This release removes all integration with bevy. benimator is no longer a bevy plugin. It is now an engine-agnostic rust library. See the announcement for more details.

    Removed (BREAKING)

    • State::animation_frame_index
    • PlayBackSpeed struct Without bevy integration, it is now possible (and easier) to alter the time duration, without the need for this struct.
    • Deprecated members

    Changed (BREAKING)

    • Rename from_range and from_iter to from_indices
    • Rename structs SpriteSheetAnimation -> Animation SpriteSheetAnimationState -> State
    • Change syntax of repeat-from to: !RepeatFrom n
    • The state is no longer automatically reset after the last frame of a run_once animation. So one must explicitly reset the state if they desire to restart the animation later.
    • [unstable-load-from-file] Remove from_(yaml|ron)_(str|bytes) functions

    New Features (BREAKING)

    • Allow to define animation FPS or total duration (on top of the existing frame-duration) Now Animation::from_iter and Animation::from_range take a FrameRate instead of a duration. The FrameRate can be created from a frame duration, total duration or a from a fps (frame-per-second).

    Minimum supported rust version (BREAKING)

    • Require the latest stable version of rust at all time

    New Features

    • Deserialize fps and 'total_duration' property
    • Implement Serialize for Animaition
    • Implement Extend<Frame> for Animation
    • Implement Eq for Animation
    • State::new constructor
    • Implementation of Default for Animation an Frame
    • State::frame_index method
    • Public update function for the state.

    Stabilization

    • Stabilize load-from-file. The feature flag is removed. The feature flag serde should be used instead.

    Documentation

    • Improve crate-level example
    • Describe better the project with goals and examples
    Source code(tar.gz)
    Source code(zip)
  • v4.0.0-rc.1(Aug 9, 2022)

    This release removes all integration with bevy!

    benimator is no longer a bevy plugin, but an engine-agnostic rust library. See the announcement for more details.

    Removed (BREAKING)

    • State::animation_frame_index
    • PlayBackSpeed struct Without bevy integration, it is now possible (and easier) to alter the time duration, without the need for this struct.
    • Deprecated members

    Changed (BREAKING)

    • Rename from_range and from_iter to from_indices
    • Rename structs SpriteSheetAnimation -> Animation SpriteSheetAnimationState -> State
    • Change syntax of repeat-from to: !RepeatFrom n
    • The state is no longer automatically reset after the last frame of a run_once animation. So one must explicitly reset the state if they desire to restart the animation later.
    • [unstable-load-from-file] Remove from_(yaml|ron)_(str|bytes) functions

    New Features (BREAKING)

    • Allow defining animation FPS or total duration (on top of the existing frame duration) Now Animation::from_iter and Animation::from_range take a FrameRate instead of a duration. The FrameRate can be created from a frame duration, total duration or a from a fps (frames-per-second).

    New Features

    • Deserialize fps and total_duration property
    • Implement Serialize for Animaition
    • Implement Extend<Frame> for Animation
    • Implement Eq for Animation
    • State::new constructor
    • Implementation of Default for Animation an Frame
    • State::frame_index method
    • Public update function for the state.

    Stabilization

    • Stabilize load-from-file. The feature flag is removed. The feature flag serde should be used instead.
    Source code(tar.gz)
    Source code(zip)
  • v4.0.0-beta.3(Aug 7, 2022)

    New Features (BREAKING)

    • Rename from_range and from_iter to from_indices
    • Allow to define animation FPS of total duration (on top of the existing frame-duration) Now Animation::from_iter and Animation::from_range take a FrameRate instead of a duration. The FrameRate can be created from a frame duration, total duration or a from a fps (frame-per-second).

    New Features

    • Deserialize fps property
    Source code(tar.gz)
    Source code(zip)
  • v4.0.0-beta.2(Aug 2, 2022)

    New Features

    • implement Serialize for Animation
    • implement Extend<Frame> for Animation
    • implement Eq for Animation
    • State::new constructor

    Removed (BREAKING)

    • implementation of Default for Animation and Frame
    Source code(tar.gz)
    Source code(zip)
  • v4.0.0-beta.1(Aug 1, 2022)

    This release removes all integration with bevy. benimator is no longer a bevy plugin, but an engine-agnostic rust library. See the announcement for more details.

    Removed (BREAKING)

    • PlayBackSpeed struct Without bevy integration, it is now already possible (and easier) to alter the time duration, without the need for this struct.
    • Deprecated members

    Changed (BREAKING)

    • Rename structs SpriteSheetAnimation -> Animation SpriteSheetAnimationState -> State
    • Change yaml syntax of repeat-from to: !RepeatFrom n
    • The state is no longer automatically reset after the last frame of a run_once animation. So one must explicitly reset the state if they desire to restart the animation later.
    • Remove from_(yaml|ron)_(str|bytes) functions

    Added

    • Add sprite_frame_index method to state
    • Public update function for the state.

    Stabilization

    • Stabilize load-from-file. The feature flag is removed. The feature flag serde should be used instead.
    Source code(tar.gz)
    Source code(zip)
  • v4.0.0-alpha.9(Jul 31, 2022)

  • v4.0.0-alpha.8(Jul 27, 2022)

    New Features

    • Stabilize load-from-file

    Removed (BREAKING)

    • (unstable-load-from-file) Remove from_(yaml|ron)_(str|bytes) functions

    Documentation

    • (ron) Document shorthand noation for ron
    Source code(tar.gz)
    Source code(zip)
  • v4.0.0-alpha.7(Jul 26, 2022)

    4.0.0-alpha.7 (2022-07-26)

    New Features (BREAKING)

    • Public update function for the state The state is no longer automatically reset after the last frame of a run_once animation. So one must explicitly reset the state if they desire to restart the animation later.

    Chore (BREAKING)

    • Remove AnimationPostUpdateSystem It had no effect. This may be reintroduced (with effect) if requested.

    Refactor (BREAKING)

    • No longer require animation to get the sprite index

    Documentation

    • Fix incorrect 'since' clause for a deprecation
    Source code(tar.gz)
    Source code(zip)
  • v4.0.0-alpha.6(Jul 17, 2022)

  • v3.7.0(Jul 17, 2022)

  • v4.0.0-alpha.5(Jul 16, 2022)

  • v4.0.0-alpha.4(Jul 15, 2022)

  • v4.0.0-alpha.3(Jul 14, 2022)

  • v4.0.0-alpha.2(Jul 13, 2022)

  • v4.0.0-alpha.1(Jul 13, 2022)

  • v3.6.1(Jul 2, 2022)

  • v3.6.0(Jun 23, 2022)

  • v3.6.0-alpha.1(Jun 22, 2022)

  • v3.5.0(Jun 22, 2022)

  • v3.4.1(Jun 21, 2022)

  • v3.4.0(Jun 20, 2022)

    3.4.0 (2022-06-20)

    Features

    • unstable-load-from-file: add from_ron_str and from_ron_bytes for SpriteSheetAnimation (44b58bc)
    • unstable-load-from-file: load animation files with .ron extension (b5288ac)
    • unstable-load-from-file: use snake_case for properties and CamelCase for enums (59bb025)
    Source code(tar.gz)
    Source code(zip)
  • v3.3.0(Jun 15, 2022)

  • v3.2.0(Jun 7, 2022)

  • v3.1.1(Jun 6, 2022)

  • v3.1.0(Jun 6, 2022)

  • v3.0.1(May 19, 2022)

  • v3.0.0(Apr 15, 2022)

  • v2.2.0(Mar 6, 2022)

  • v2.1.0(Mar 2, 2022)

Owner
Jonathan Cornaz
Loving Kotlin, Rust and Elm
Jonathan Cornaz
Explicitly set sprite layers for sprites in Bevy games.

extol_sprite_layer lets you specify the drawing order for sprites in your Bevy game using a separate component rather than via the z-coordinate of you

Ash 5 May 2, 2023
A light-weight Anchor-Offset based 2D sprite rendering system for the bevy engine.

Bevy AoUI A light-weight anchor-offset based 2D sprite layout system for the bevy engine. Bevy AoUI provides a light-weight rectangular anchor-offset

Mincong Lu 4 Nov 22, 2023
πŸ€Ήβ€ 2D sprite rendering extension for the specs ECS system

specs-blit 2D sprite rendering extension for the Specs ECS system. All sprites are loaded onto a big array on the heap. Example // Setup the specs wor

Thomas Versteeg 8 Aug 14, 2022
πŸ“Ί An implementation of the retro bouncing DVD logo screensaver animation built with bevy and rust

?? Bevy bouncing DVD logo This project is a simple demonstration of using the Bevy game engine and the Rust programming language to create a bouncing

Victor Aremu 5 Jan 12, 2023
Action-based animation system for Bevy.

bevy_action_animation Action-based animation system for Bevy. Introduction This plugin provides users of the Bevy game engine with an action/trigger-b

undersquire 5 Apr 15, 2023
Animation graphs in Bevy!

bevy_animation_graph Motivation Animation graphs are an essential tool for managing the complexity present in the animation pipelines for modern 3D ga

Manuel Brea Carreras 11 Dec 18, 2023
Bevy Simple Portals is a Bevy game engine plugin aimed to create portals.

Portals for Bevy Bevy Simple Portals is a Bevy game engine plugin aimed to create portals. Those portals are (for now) purely visual and can be used t

Sélène Amanita 11 May 28, 2023
Interoperation with the Automaton animation engine

Automaton-rs an interopt layer for the Automaton animation engine for creative coding

Aaron Bies 9 Sep 18, 2021
A Bevy plugin for loading the LDtk 2D tile map format.

bevy_ldtk ( Tileset from "Cavernas" by Adam Saltsman ) A Bevy plugin for loading LDtk tile maps. Usage use bevy::prelude::*; use bevy_ldtk::*; fn mai

Katharos Technology 23 Jul 4, 2022
Inspector plugin for the bevy game engine

bevy-inspector-egui This crate provides the ability to annotate structs with a #[derive(Inspectable)], which opens a debug interface using egui where

Jakob Hellermann 517 Dec 31, 2022
A plugin for Egui integration into Bevy

bevy_egui This crate provides a Egui integration for the Bevy game engine. Features: Desktop and web (bevy_webgl2) platforms support Clipboard (web su

Vladyslav Batyrenko 453 Jan 3, 2023
Crossterm plugin for the bevy game engine

What is bevy_crossterm? bevy_crossterm is a Bevy plugin that uses crossterm as a renderer. It provides custom components and events which allow users

null 79 Nov 2, 2022
A Bevy plugin to use Kira for game audio

Bevy Kira audio This bevy plugin is intended to try integrating Kira into Bevy. The end goal would be to replace or update bevy_audio, if Kira turns o

Niklas Eicker 172 Jan 5, 2023
A prototype plugin providing a simple line drawing api for bevy.

bevy_debug_lines A prototype plugin providing a simple line drawing api for bevy. See docs.rs for documentation. Expect breakage on master. Click on t

Michael Palmos 92 Dec 31, 2022
Bevy plugin helping with asset loading and organisation

Bevy asset loader This Bevy plugin reduces boilerplate when loading game assets. The crate offers the AssetCollection trait and can automatically load

Niklas Eicker 205 Jan 2, 2023
A Bevy Engine plugin for making 2D paths, smooth animations with Bezier curves

bevy_pen_tool A Bevy Engine plugin for making 2D paths and smooth animations with Bezier curves TODO: Mesh-making functionality for building 2D shapes

Eli 36 Dec 22, 2022
A procedural sky plugin for bevy

bevy_atmosphere A procedural sky plugin for bevy Example use bevy::prelude::*; use bevy_atmosphere::*; fn main() { App::build() .insert_re

Jonah Henriksson 137 Dec 23, 2022
Generic cellular automaton plugin for bevy.

Bevy Cellular Automaton bevy_life is a generic plugin for cellular automaton. From the classic 2D Conway's game of life to WireWorld and 3D rules, the

FΓ©lix Lescaudey de Maneville 34 Nov 23, 2022
Verlet physics plugin for bevy.

bevy_verlet Simple Verlet points and sticks implementation for bevy. Features You can simply add a VerletPoint component on any entity with a Transfor

FΓ©lix Lescaudey de Maneville 34 Dec 9, 2022