Cocos2d JS v3: Callback when an action is finished

I would like to run a JS function when an action is finished. I know I can poll for isDone(), but is there a better way, perhaps using events?

node.runAction(action) followed by a setTimeout with the same amount of time is always a little bit off, so it is not usable.

Use sequence action

node.runAction(
    cc.sequence( action, cc.callFunc(func, target) )
);
1 Like

I tried to use an example:

node.runAction(
    cc.sequence( action, cc.callFunc(func, target) )
);

but I unfortunately func () is executed without waiting for end of the action

var funct = function(){
        var second = cc.moveBy(2, 300, 0);
        sprite.runAction(second);
        alert("funct run");
    };
sprite.runAction(cc.sequence( cc.moveBy(5, -50, 0), cc.moveBy(2, 0, 200), cc.callFunc(funct(), this)));   

Please tell me where is my mistake? Thanks!

Try without the (): funct instead of funct()
sprite.runAction(cc.sequence( cc.moveBy(5, -50, 0), cc.moveBy(2, 0, 200), cc.callFunc(funct, this)));

1 Like

Alek76, thank you so much! It helped me!

Is there any way to have the callback called after each frame rather than only at the end ?