How to delay one line of code?

I have a physics sprite that I want to remove from it’s parent AFTER I run some animation on it.
So this is what I have:

this.object.sprite.runAction(this.animateExplosion);
this.object.removeFromParent();

What is the best way to delay the removeFromParent line until the runAction animation is done running (going through all the frames) which is less than a second. Should I use sequence? Should I use setTimeout? Use something else?

hello, as far as I am concerned, sequence is a possible solution for you in this case. :smile:
Have u had some experience with Admob on android (cocos2d-js). please help me to integrate admob with my JS game :smiley:

Thanks for the reply.

I haven’t used Admob yet (also with my cocos2d-x JS game) but I do plan on using it in the near future. Just as soon as my game is done. Feel free to stay in touch on Twitter and we’ll post about our experience using it…when I get around to it eventually.

1 Like

I am still having the same issue. I am using Cocos2D-x v3.7
This is what I tried:

var delay = cc.delayTime(5);
var callFunc1 = cc.callFunc(cc.log("test1"), this);
var callFunc2 = cc.callFunc(cc.log("test2"), this);

var sequenceAction = new cc.Sequence(callFunc1, delay, callFunc2);
this.sprite.runAction(sequenceAction);

Both test1 and test2 are being logged at the same time. It’s like the delay is not doing anything.