Skip to content

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

Description

@echoptic

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`!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions