Code Monkey home page Code Monkey logo

benimator's Introduction

Benimator

License Crates.io rustc Docs

A sprite animation library for rust game development.

Initially designed for bevy, it is now engine agnostic.

Goals

This project aim to provide the building the blocks to facilitate 2d sprite animation with any game engine.

Non-goals

Benimator is not rendering anything. It only keeps track of sprite indices.

One is expected to use benimator with a game engine such as bevy.

How it looks like

At its core benimator is an Animation data structure and a State to track the frame-index as time pass.

// Create an animation
let animation = Animation::from_indices(0..=3, FrameRate::from_fps(10.0));

// Create a new animation state
let mut state = State::new();

// In the game loop, for each update, tell the state how much time has elapsed
let delta_time = Duration::from_millis(250);
state.update(&animation, delta_time);

// Then get the current frame index.
// (so that we can tell our engine to render the sprite at that index)
assert_eq!(state.frame_index(), 2);

Have a look at the examples for complete examples using the bevy game engine.

Installation

benimator is published on crates.io

You can add the dependency to your cargo file with:

cargo add benimator

Cargo features

Feature Description
serde Implementations of Serialize and Deserialize

Feature flags not mentioned here are NOT part of the public API and are subject to breaking changes!

MSRV

The minimum supported rust version is currently 1.70.

It can be updated to a newer stable version when required, and that will not be considered a breaking change (it can happen in for a minor or patch release).

License

Licensed under either of

at your option.

benimator's People

Contributors

aaneto avatar cristicbz avatar dependabot[bot] avatar edwardvear avatar flipbit03 avatar github-actions[bot] avatar jcornaz avatar johnteske avatar kpence avatar renovate[bot] avatar semantic-release-bot avatar tguichaoua avatar thedodd avatar xion avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

benimator's Issues

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.34
  • rstest 0.19.0
  • anyhow 1.0
  • toml 0.8.12
  • rustc_version 0.4.0
github-actions
.github/workflows/check.yml
  • actions/checkout v4
  • Swatinem/rust-cache v2
  • taiki-e/install-action v2
  • actions/checkout v4
  • Swatinem/rust-cache v2
  • taiki-e/install-action v2
.github/workflows/create-release.yml
  • actions/checkout v4
  • taiki-e/create-gh-release-action v1

  • Check this box to trigger a request for Renovate to run again on this repository

Ping Pong mode

Let's say I want to animate pacman. In that case, the animation mode I want is PingPong.

For example I could define the frame range to 0..=3 and the animation would loop like this: 0 1 2 3 2 1 0 1 2 3 ... forever.

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 ๐Ÿ‘ ๐Ÿ™Œ โค๏ธ

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 ๐Ÿƒ without resorting to recreating the animation frames from scratch ๐Ÿ˜ต

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 ๐Ÿค– ๐Ÿƒ

Allow to define animation FPS

We more often think of animaton speed in terms of "frame-per-second" that "frame-duration".

Therefore, the user should be able to define the animation FPS. (frame-duration = 1 / FPS)

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.

Prefer using Events to notify end of animations

I found this incredible crate and use it for some cool game dev, it was really fun!

However, I also worked with the newly released bevy_tweening crate and needed a way to detect the end of animations to do some stuff. I proposed that we could use the same technique as you are using: removing a Play component. Unfortunately, we asked some ECS peeps about doing that compared to using Events instead, their answer was that we should prefer using Events for performances reasons.

I know that the Play component plays more than this role of detecting the end of an animation, but maybe you would be interested in this. As I understand it is preferable to avoid adding/removing components too much from the ECS and prefer doing things like in bevy_tweening by using the Animator and changing its state.

on demand animation

How can I have animation to run once on demand? I need to show shot splash animation each time player does a shot. I see 2 options here:

  1. on each shot to add a new entity with SpriteSheetBundle and animation and then track Play component removal and remove whole this entity. But this way I will remove all entities that jsut lost Play component, not only shot animation entity.
  2. create entity beforehand with SpriteSheetBundle and animation but without Play component and with visibility: Visibility{is_visible: false},. And then on each shoot to add Play component in it and set up visibility to true. The problem here is how do I differ shot animation entity from other animation entities?

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.

Allow to define animation duration

Sometimes, especially for visual effects or one-shot animations, it is helpful to define the whole animation duration rather than its speed.

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

  • fix crash when one frame duration is zero
  • make it easier to write an animation file when all frames have the same duration
  • configure documentation so that the new API shows up on docs.rs
  • ron support
  • gate yaml and ron behind feature flags (in addition of the load-from-file gate)
  • document shorthand notation for ron
  • implicit_some for ron
  • 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

  • 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.
  • 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)
  • 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.

Play Component Should be SparseSet

Given that the play component is meant to trigger or pause animations, it should use SparseSet storage instead of Archetype storage to prevent archetype table copy. This could be a significant overhead if one has a large number of animated entities that need to be paused all at once (say the user presses pause and that needs to pause all animations)

feat: Compile-time "Animation" creation

Current Behavior

Currently, the Animation structures are constructed at runtime, which works well for dynamic and interactive applications.

Desired Feature

I propose adding the capability to build Animation structures at compile time. This feature would allow developers to define animations that are static and unchanging throughout the application's life, ensuring these animations are constructed and optimized during compilation, reducing runtime overhead and potentially improving the application's overall performance. (The main reason is for design purposes)

Possible Implementation

I believe this feature could be implemented by providing a macro or a set of const functions that allow for the construction of Animation structures with fixed parameters. This way, developers can opt-in to compile time construction where it makes sense for their application.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.