13 releases (8 breaking)
0.9.0 | Dec 23, 2024 |
---|---|
0.8.1 | Jul 30, 2024 |
0.7.2 | Apr 3, 2024 |
0.7.1 | Mar 31, 2024 |
0.2.0 | Dec 26, 2022 |
#476 in Game dev
163 downloads per month
42KB
428 lines
Aseprite plugin for Bevy
A plugin for using Aseprite animations in Bevy.
The Aseprite
component requires Bevy's Sprite
and
contains two fields:
- asset:
Handle<AsepriteAsset>
- anim:
AsepriteAnimation
.
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.
Dependencies
~41–73MB
~1.5M SLoC