Libgdx: Action.OnCompletionListener

Created on 14 Feb 2014  ·  3Comments  ·  Source: libgdx/libgdx

I wasn't able to find a way to check if a special Action (parallel to some others on the same actor) has finished. Something like an Interface Action.OnCompletionListener like Music.OnCompletionListener would be really nice.

Action a = Actions.fadeOut(10);
a.setOnCompletionListener(new Action.OnCompletionListener() {
//do something.
})

Is there a special reason why there is nothing like this integrated?

Most helpful comment

You can use:

sequence(someAction, new Action() {
    public boolean act (float delta) {
        // This runs when someAction is done.
        return true;
    }
});
// OR, one line of code less:
sequence(someAction, run(new Runnable() {
    public void run () {
        // This runs when someAction is done.
    }
}));

I can't think of a scenario where a completion listener would be more useful.

All 3 comments

You can use:

sequence(someAction, new Action() {
    public boolean act (float delta) {
        // This runs when someAction is done.
        return true;
    }
});
// OR, one line of code less:
sequence(someAction, run(new Runnable() {
    public void run () {
        // This runs when someAction is done.
    }
}));

I can't think of a scenario where a completion listener would be more useful.

Oh well, that's good! Thanks a lot. Did not know that you can integrate your own Actions so easy.

By the way, could you please explain to me what an AfterAction does (Actions.after(Action))? I could not figure out what. Stumbled over it while searching for a listener method.

Yep, the whole idea with actions is you can easily write your own. :)

AfterAction "Executes an action only after all other actions on the actor at the time this action was added have finished." So you add the action and it doesn't complete until all other actions are done. You can use this to block a sequence to make things happen after other things.

CountdownEventAction is another way to control having actions happen after other things. See this thread and the blog post linked from there:
http://www.badlogicgames.com/forum/viewtopic.php?t=12322&p=56104

Was this page helpful?
0 / 5 - 0 ratings