#bevy #aseprite #mod

bevy_mod_aseprite

A plugin for using Aseprite animations in Bevy

6 releases (breaking)

0.5.0 Jul 17, 2023
0.4.1 Jul 4, 2023
0.4.0 Mar 12, 2023
0.3.0 Jan 1, 2023
0.1.0 Dec 23, 2022

#256 in Game dev

Download history 2/week @ 2023-06-03 13/week @ 2023-06-10 7/week @ 2023-06-17 6/week @ 2023-06-24 28/week @ 2023-07-01 28/week @ 2023-07-08 24/week @ 2023-07-15 9/week @ 2023-07-22 6/week @ 2023-07-29 14/week @ 2023-08-05 10/week @ 2023-08-12 25/week @ 2023-08-19 15/week @ 2023-08-26 12/week @ 2023-09-02 7/week @ 2023-09-09 18/week @ 2023-09-16

54 downloads per month

MIT/Apache

35KB
385 lines

Aseprite plugin for Bevy

latest doc

A plugin for using Aseprite animations in Bevy.

The AsepriteBundle is composed of the same fields as the SpriteSheetBundle but with two extra components, Handle<Aseprite> and AsepriteAnimation.

Example

Aseprite Example

See examples/aseprite.rs for a complete example, you can run it with:

cargo run --example aseprite

Usage

Basic usage is as follows:

fn load_assets(asset_server: Res<AssetServer>, mut aseprite_handles: ResMut<AsepriteHandles>) {
    let player: Handle<Aseprite> = asset_server.load("player.ase");
    aseprite_handles.push(player);
}

fn setup(
    mut commands: Commands,
    aseprite_handles: Res<AsepriteHandles>,
    aseprites: Res<Assets<Aseprite>>,
) {
    let aseprite_handle = &aseprite_handles[0];
    let aseprite = aseprites.get(aseprite_handle).unwrap();
    let animation = AsepriteAnimation::new(aseprite.info(), "idle");

    commands
        .spawn(Player)
        .insert(AsepriteBundle {
            texture_atlas: aseprite.atlas().clone_weak(),
            sprite: TextureAtlasSprite::new(animation.current_frame()),
            aseprite: aseprite_handle.clone_weak(),
            animation,
            ..default()
        });
}

#[derive(Resource, Deref, DerefMut, Default)]
struct AsepriteHandles(Vec<Handle<Aseprite>>);

The component AsepriteAnimation also exposes methods to get information such as the current animation frame (within the tag or not), its duration, or the number of remaining frames. This can be useful to transition states at the end of an animation:

fn transition_player(
    time: Res<Time>,
    player_q: Query<(&PlayerState, &Handle<Aseprite>, &AsepriteAnimation), With<Player>>,
    aseprites: Res<Assets<Aseprite>>,
    mut ev_player_changed: EventWriter<PlayerChanged>,
) {
    let (&player_state, handle, anim) = player_q.single();
    let aseprite = aseprites.get(handle).unwrap();
    match player_state {
        PlayerState::Attack => {
            let remaining_frames = anim.remaining_tag_frames(aseprite.info()).unwrap();
            let frame_finished = anim.frame_finished(time.delta());
            if remaining_frames == 0 && frame_finished {
                ev_player_changed.send(PlayerState::Stand.into());
            }
        }
        _ => (),
    }
}

Bevy Compatibility

bevy bevy_mod_aseprite
0.11 0.5
0.10 0.4
0.9 0.2, 0.3
0.8 0.1

History

This crate started as a fork of mdenchev/bevy_aseprite.

Dependencies

~27–70MB
~1M SLoC