#bevy #aseprite #animation

bevy_mod_aseprite

A plugin for using Aseprite animations in Bevy

14 releases (9 breaking)

Uses new Rust 2024

0.10.0 Apr 30, 2025
0.9.0 Dec 23, 2024
0.8.1 Jul 30, 2024
0.7.1 Mar 31, 2024
0.2.0 Dec 26, 2022

#488 in Game dev

Download history 3/week @ 2025-02-05 6/week @ 2025-02-12 2/week @ 2025-02-19 19/week @ 2025-02-26 8/week @ 2025-04-16 130/week @ 2025-04-30

138 downloads per month

MIT/Apache

44KB
438 lines

Aseprite plugin for Bevy

latest doc

A plugin for using Aseprite animations in Bevy.

The Aseprite component requires Bevy's Sprite and contains two fields:

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 ase_handles: ResMut<AsepriteHandles>) {
    let player = asset_server.load("player.ase");
    ase_handles.push(player);
}

fn setup(
    mut commands: Commands,
    ase_handles: Res<AsepriteHandles>,
    ase_assets: Res<Assets<AsepriteAsset>>,
) {
    let ase_handle = &ase_handles[0];
    let ase_asset = ase_assets.get(ase_handle).unwrap();
    let anim = AsepriteAnimation::new(ase_asset.info(), "idle");
    commands.spawn((
        Player,
        Sprite {
            image: ase_asset.texture().clone_weak(),
            texture_atlas: Some(TextureAtlas {
                index: anim.current_frame(),
                layout: ase_asset.layout().clone_weak(),
            }),
            ..default()
        },
        Aseprite {
            anim,
            asset: ase_handle.clone_weak(),
        },
    ));
}

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

The AsepriteAnimation struct also exposes methods to get information such as the current animation frame (within a tag or not), its duration, and 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, &Aseprite), With<Player>>,
    aseprites: Res<Assets<AsepriteAsset>>,
    mut ev_player_changed: EventWriter<PlayerChanged>,
) -> Result {
    let (&player_state, ase) = player_q.single()?;
    let ase_asset = aseprites.get(&ase.asset).unwrap();
    // Change the player state to idle at the end of the attack animation
    if let PlayerState::Attack = player_state {
        let remaining_frames = ase.anim.remaining_tag_frames(ase_asset.info()).unwrap();
        let frame_finished = ase.anim.frame_finished(time.delta());
        if remaining_frames == 0 && frame_finished {
            ev_player_changed.send(PlayerState::Stand.into());
        }
    }
    Ok(())
}

Bevy Compatibility

bevy bevy_mod_aseprite
0.16 0.10
0.15 0.9
0.14 0.8
0.13 0.7
0.12 0.6
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

~45–77MB
~1.5M SLoC