Lommix / bevy_aseprite_ultra

The ultimate bevy aseprite binary plugin. Featuring animations and static atlas loading with pivots. Full support for hot reloading!
MIT License
35 stars 10 forks source link

Is there any ergonomic api for user change there tag? #3

Closed darkautism closed 6 months ago

darkautism commented 6 months ago

For example, I would like my character to have tags such as idle, attack, and die, and be changed by the external system when the game changes.

onelson commented 6 months ago

I have also been trying to figure this out 😅

For my use case, I've got a series of looped tags, and I want to activate one or the other, interrupting the current regardless of how far along into the frame range it is.

I tried a number of approaches, but nothing quite worked. Initializing a fresh Animation and assigning it to a Mut<Animation> seems to break playback.

The closest I got was querying for the Animation component and setting its tag field directly, but doing this end up playing frames from outside the tag's range during the transition.

Not sure what my options are today.


Edit: I did manage to get something working, but in an ugly way. I had to add AnimationState to the public exports, and also mark the current_frame field as pub.

// ....
} else if action_state.pressed(&PlayerAction::Crouch) {
    if animation.tag.as_deref() != Some("Crouch") {
        animation.tag = Some(String::from("Crouch"));
        anim_state.current_frame = 2;
    }
} else {
// ...

By setting the current_frame directly to the first frame of the tag's range, things seem to look okay.

Obviously, this is far from ideal, but it's something. Assuming there's a way I can look up the start frame of the tag I'll be unblocked, but this seems like a great use case to solve in a nicer way 😉

Lommix commented 6 months ago

I merged your request and also added a new function 'play' for the animation component, that lets you switch tags more easily.

onelson commented 6 months ago

Animation::play() is working well for me, thanks 🙏🏻