Skip to content

Multirious/bevy_tween

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Crates.io Version Crates.io License Docs.rs

bevy_tween

Bevy procedural and keyframe animation library.

This is a young plugin and APIs are to be fleshed out. Breaking changes are to be expected!

See changelog here.

Features

  • Ergonomic and user-friendly API: You can always spawn the animator manually but this crate provide APIs that abstracted over most boilerplate code. Animation can be built using the builder with function combinators.

    Example
    let sprite_id = commands.spawn(SpriteBundle { ... }).id();
    let sprite = sprite_id.into_target();
    commands.animation()
        .insert(tween(
            Duration::from_secs(1),
            EaseFunction::Linear,
            sprite.with(translation(pos0, pos1))
        ));

    You can also abstract animation!

    fn my_animation(
        target: TargetComponent,
        duration: Duration
    ) -> impl FnOnce(&mut AnimationCommands, &mut Duration) {
        parallel((
            tween(duration, EaseFunction::QuadraticOut, target.with(translation(...))),
            tween(duration, EaseFunction::QuadraticOut, target.with(rotation(...))),
        ))
    }
    
    let sprite_id = commands.spawn(Sprite { ... }).id();
    let sprite = sprite_id.into_target();
    commands.animation().insert(my_animation(sprite, Duration::from_secs(1)))
  • Flexible and Extensible: This crate is built on top of bevy_time_runner which mean we can extend this crate by adding any components and systems.

    • Tween anything from anywhere, built-in or custom system.
    • Interpolate with any curve, built-in or custom system.
    • Anything else.
  • Parallelism: Tweens are typed and can be query over by their typed system which increase chances for system parallelism.

  • Rich timer control:

    • Looping
    • Time scaling
    • Skip backward or forward
    • Jumping to anywhen

See demos

Goals:

  • Flexible ๐ŸŽ‰
  • integration with other crates (?)
    • bevy_animation
    • bevy_lookup_curve
  • Editor. While the original goal for this crate is tweening from code, this crate absolutely has the capability to work on any complex animations. The editor will aid in such jobs.
    • Real-time display at any point in time in the animation.
    • Editing path from point A to point B with arbitary curve.

Differences and how it works

This crate chose a different approach to storing tween data/input to solve flexibility issues present in bevy_tweening or bevy_easings, like difficulty tweening in parallel or sequence of multiple types.

This approach offers:

  • As mentioned above, capability to tween in parallel, sequence, or overlapping of any types.
  • Extendability. And not just for tweening. For example, this crate adds a custom event plugin that can emit arbitrary events anytime in the animation by just building off the same system.

How it works:

  1. By building on top of bevy_time_runner, an animator is a tree of entities.
  2. The parent is TimeRunner. This entity handles all the timing and progress of its children.
  3. The children can be any combination of any components, such as tweens by this crate.
  4. Systems are then run in a pipeline, communicating through various dependency-injected components.

Feature gates

  • Defaults
    • bevy_asset
      Add tweening systems for asset.
    • bevy_render
      Currently add nothing but required by the bevy_sprite feature.
    • bevy_sprite
      Add some built-in interpolators related to sprite.
    • bevy_ui
      Add some built-in interpolators related to ui.
    • bevy_eventlistener
      Add entity-targeted events with bevy_eventlistener.
  • Optional

Bevy Version Support

bevy bevy_tween
0.14 0.6
0.13 0.2โ€“0.5

Credits

  • bevy_tweening

    The first crate I discovered and tried to do tweening with in Bevy. Their method of Lens is great and so it's present in this crate. Now called Interpolator. Usages may be similar but is implemented differently.

  • godot

    Godot's tween make it simple to animate something which is the inspiration for this crate. The multi-entity architecture is mainly inspired by Godot's node child-parent hierarchy system and that most of the engine APIs utilizes this to define behavior.

Contributions

Contributions are welcome!

License

Licensed under either of

at your option.

Your contributions

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Demos

cargo run --example follow -F bevy/bevy_winit
A square will follow your circle with configurable animation.

follow.mp4

cargo run --example click -F bevy/bevy_winit
Click left to spawn a circle. Hold right click to repetitively spawn a circle every frame.

hm.mp4

cargo run --example hold -F bevy/bevy_winit
Hold left click to increase the effect intensitiy.

hold.mp4

cargo run --example event -F bevy/bevy_winit
Showcasing the tween event feature.

2024-04-14.15-52-03.mp4

cargo run --example sprite_sheet -F bevy/bevy_winit
Sprite Sheet animation.

2024-04-14.15-42-44.mp4