Callback while action is running

I need my callback function to execute ALL THE WHILE that an action is running, and also know how much time has passed so far and what is the node that is running the action.

For javascript example, I only found how to run the callback AT THE END. But I need it to run the whole time.

BTW, I am converting from spritekit to cocos2d-js. The code for spritekit is like this…

[self runAction: [SKAction customActionWithDuration:dSecondsForAction
                                    actionBlock:^(SKNode *node, CGFloat elapsedTime) {
                                        node.xScale = someStrangeFunction(elapsedTime);
                                    }] ];

Do you mean that you need run two functions simultaneously in your action? Something like spawn function or not?

var someStrangeFunction1 = cc.callFunc(funtion(){});
var someStrangeFunction2 = cc.callFunc(funtion(){});
this.runAction(cc.spawn(someStrangeFunction1, someStrangeFunction2));

Thank you for responding. I only need one function to run during the action. However, I need this one function to be called over and over until the action is finished. In the example I gave, the function simply has the job of setting the xScale of the node in consideration of how much time has passed.

Unfortunately I’m not good in spritekit, But I think I understand what are you need. I’ll try to imagine again.

so you have the action for scaling some object:

this.runAction(cc.scaleTo(1, someNewScaleX, someNewScaleY))

and than you need apply easing

howToPlayBtn.runAction(cc.scaleTo(1, someNewScaleX, someNewScaleY).easing(
{
	easing: function (elapsedTime) {
		return someStrangeFunction(elapsedTime);
	}
}
));
1 Like

Wow, that’s very interesting. I did already learn something about easing, but I thought I could only choose from the predefined easing functions. I did not know that I could make my own easing function in the way you have shown. Thanks very, very much!

1 Like