Animation action is complete

Hi, I would like to know how I can detect whether an animation action is complete. This is necessary when I want to start a new animation but have to wait before the current one is finished. For example:

Player presses jump, blend from idle animation to jumpStart animation.
…Waiting for what is happening…
Ah, character is floating in air, start jumpLoop right after current animation.

Are there ways to do this? Because right now I think the jumpStart animation is only executed very shortly as it immediately detects it is in air.

Here you can find some ideas

Perhaps these examples can help you:

1 Like

Thanks for your answer. I see it is indeed possible to do it this way. However, this way involves Java Reflection, and I’d like to stay away from that. I don’t think reflection is a good thing and should be used as little as possible. At work I have only ever used it with generated Java code, as there was no other way to deal with that. What is the reason the AnimEventListener was not migrated to the new animation system?

Note, you can create your own tween (that takes a Runnable for example) if you do not want to use the CallMethod.

1 Like

You are right, that works!

public class EventAction extends BaseAction {

    private List<ActionDoneEventListener> subscribers = new LinkedList<>();

    public EventAction(Tween tween) {
        super(tween);
    }

    public void subscribe (ActionDoneEventListener subscriber) {
        this.subscribers.add(subscriber);
    }

    @Override
    public boolean interpolate(double t) {
        boolean running = super.interpolate(t);
        if (!running) {
            subscribers.forEach(s -> s.onComplete(this));
        }
        return running;
    }
}
1 Like