Resting state for sprite animation

(Sergey Veselkov) #1

Player has 4 animations for each side of the movement and 4 rest states.
How can I change the state of rest depending on the direction of movement?

The RestState has no methods to modify it and EndControl::Loop, after abort a animation, leaves the last processed sprite.

I think I can change EndControl to Stay before abort a animation and put the rest state at the end of each animation, but maybe there is a better solution?

0 Likes

(Azriel Hoh) #2

So, hopefully this is relevant:

use amethyst::animation::{get_animation_set, ControlState};

let animation_set = get_animation_set(&mut animation_control_sets, entity)
    .expect("Animation should exist as entity should be valid.");

let sequence_ended = {
    animation_set
        .animations
        .iter()
        .find(|&&(ref id, ref _control)| id == unimplemented!("Your animation ID"))
        .map_or(true, |(_id, control)| control.state == ControlState::Done)
};

if sequence_ended {
    // start new animation
}

and for “start new animation”, maybe swap() is useful:

1 Like

(Sergey Veselkov) #3

The problem is not to change one animation for another. The problem is to choose a sprite after abort a animation.
After aborting a animation with normal end control it return to RestState, which I can’t modify (but I probably can create a new one).
I think I can put the right sprite at the end of each animation and use the stay end control, but it’s not really cool.

Actually I would like to use the “Loop (None)” end control, but it stops at the current sprite animation, which is absolutely not suitable.
Perhaps it is worth adding the function abort_with(Id, EndControl) to AnimationControlSet for this case.
Or maybe even something like abort_with(Id, sprite_number).

0 Likes

(Azriel Hoh) #4

ah, think I understand. Have done a similar thing in my game with a system that reads in the current sequence (e.g. Walking<Left/Right/Up/Down>), and the sequence status (Begin/Ongoing/End), and when it’s on End, there’s logic per sequence that decides what to return to.

With the amethyst_animation crate, because the SpriteRender needs a resting state SpriteRender component attached to the entity, in your case the system could do something like:

// feels a bit weird to change the "resting state" sprite render,
// but demonstrates the concept
if sequence_ended { // see earlier post
    let correct_resting_state_sprite_render = match walk_direction { .. };
    sprite_render_component_storage
        .insert(entity, correct_resting_state_sprite_render)?;
}
0 Likes

(Sergey Veselkov) #5

Well, I create a new RestState every time a character turns and it works.

But what’s wrong with abort a animation with EndControl::Loop? Is it really useful that it’s stays on the current sprite and doesn’t return to RestState?

0 Likes

(Azriel Hoh) #6

there shouldn’t be anything wrong, think I used to do that for some animations (e.g. mid air jumping animation until the character touches the ground).

It’s more likely to be a case of “the animation crate is functional, but not ergonomic / polished”, so it doesn’t behave nicely without code telling it to. Rhuagh did mention a (long-ish) while ago that it’s not yet user-facing

0 Likes