mdenchev / bevy_aseprite

52 stars 26 forks source link

How to change to an animation from a different aseprite file? #19

Open echoptic opened 7 months ago

echoptic commented 7 months ago

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`!
nshardy commented 3 months ago

Out of curiosity, why did you separate your animations into different files instead of tagging them as certain animations in Aseprite?

It seems like it would be easier to tag them instead of changing files.

seivan commented 1 month ago

Out of curiosity, why did you separate your animations into different files instead of tagging them as certain animations in Aseprite?

It seems like it would be easier to tag them instead of changing files.

Just a guess, but if you're packing textures, you might keep each individual animation in its own atlas/sheet. Helps with batch rendering if they're all the same file. If it's detailed animation they might not all fit in the same file.