Skip to content

A plugin for using Aseprite animations in Bevy

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

lerouxrgd/bevy_mod_aseprite

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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>,
) {
    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());
        }
    }
}

Bevy Compatibility

bevy bevy_mod_aseprite
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.

About

A plugin for using Aseprite animations in Bevy

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages