| Crates.io | bevy_mod_aseprite |
| lib.rs | bevy_mod_aseprite |
| version | 0.14.0 |
| created_at | 2022-12-23 23:56:44.212679+00 |
| updated_at | 2026-01-20 22:56:56.623379+00 |
| description | A plugin for using Aseprite animations in Bevy |
| homepage | |
| repository | https://github.com/lerouxrgd/bevy_mod_aseprite |
| max_upload_size | |
| id | 744767 |
| size | 189,432 |
A plugin for using Aseprite animations in Bevy.
The Aseprite component requires Bevy's Sprite and
contains two fields:
Handle<AsepriteAsset>AsepriteAnimation.
See examples/aseprite.rs for a complete example, you can run it with:
cargo run --example aseprite
Basic usage is as follows:
use bevy_mod_aseprite::prelude::*;
#[derive(Resource, Deref, DerefMut, Default)]
struct AsepriteHandles(Vec<Handle<AsepriteAsset>>);
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.atlas_texture.clone(),
texture_atlas: Some(TextureAtlas {
index: anim.current_frame(),
layout: ase_asset.atlas_layout.clone(),
}),
..default()
},
Aseprite {
anim,
asset: ase_handle.clone(),
},
));
}
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: MessageWriter<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 | bevy_mod_aseprite |
|---|---|
| 0.18 | 0.14 |
| 0.17 | 0.11, 0.12, 0.13 |
| 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 |
This crate started as a fork of mdenchev/bevy_aseprite.