I have these 2 aseprite files imported:
mod sprites {
use bevy_aseprite::aseprite;
aseprite!(pub KnightIdle, "Heroes/Knight/Idle/Idle.aseprite");
aseprite!(pub KnightRun, "Heroes/Knight/Run/Run.aseprite");
}
And I tried changing the animation in a system like this:
fn change_animation(
mut query: Query<&mut Handle<Aseprite>, With<Knight>>,
keyboard_input: Res<Input<KeyCode>>,
asset_server: Res<AssetServer>,
) {
for mut aseprite in &mut query {
if keyboard_input.just_pressed(KeyCode::Space) {
*aseprite = asset_server.load(sprites::KnightRun::PATH);
}
}
}
but when the animation changes i get a crash:
thread '<unnamed>' panicked
Sprite index 4 does not exist for texture atlas handle AssetId<bevy_sprite::texture_atlas::TextureAtlas>{ index: 0, generation: 1}.
Encountered a panic in system `bevy_sprite::render::extract_sprites`!
I have these 2 aseprite files imported:
And I tried changing the animation in a system like this:
but when the animation changes i get a crash: