Sequence not running actions in order

My goal is to disable input before the sprite has completed moving and rotating to 0 degrees and then re-enable it after these actions finish animating. I am using the code:

buck.stopAllActions();
buck.runAction (cc.moveTo( moveTime , event.getLocation() ));
buck.runAction(cc.sequence(

                    cc.callFunc(theMouse.setEnabled(false)),
                    cc.callFunc(cc.log(theMouse.isEnabled())),
                    cc.rotateTo( rotateTime, at ),
                    cc.delayTime(moveTime),
                    cc.rotateTo(pivotTime, 0),
                    cc.callFunc(theMouse.setEnabled(true)),
                    cc.callFunc(cc.log(theMouse.isEnabled()))

                ));

When I click the screen my console instantly says false, true which means the first and last actions in the sequence are being run before my cc.rotateTo action has even run. Right? How can I fix this? If there is a better way to implement this behavior I would love to know that as well. Thanks guys.

You’re using cc.callFunc incorrectly. For example, you’re immediately calling theMouse.setEnabled(false) when you create your first cc.callFunc, and the return value of the function theMouse.setEnabled(false), which is probably void, is passed as the argument to your cc.callFunc constructor. No bueno, and I’m sure this would crash if you tried to run it on a device in native code instead of pure javascript.

To have cc.callFunc execute your method as expected, you need to pass it all of the information needed to call your function at the appropriate time, like this:

cc.callFunc(theMouse.setEnabled, theMouse, false);

The first parameter is the function to call, the second parameter is the object on which to call the function, and the 3rd parameter is whatever argument you want to pass to the called function (in this case, false). When the proper time comes for the cc.callFunc to run, it will use that information to execute your theMouse.setEnabled(false) function call.

Creating the second cc.callFunc where you are trying to do some logging is a little more tricky, because you’re actually trying to kick off two functions at the same time: the cc.log function and theMouse.isEnabled. You can do that, but I’m too lazy to write up how. Once you get a grasp on cc.callFunc, you can figure it out. Your sequence, without the logs, should look something like this:

cc.callFunc(theMouse.setEnabled, theMouse, false);
cc.rotateTo( rotateTime, at ),
cc.delayTime(moveTime),
cc.rotateTo(pivotTime, 0),
cc.callFunc(theMouse.setEnabled, theMouse, true);
1 Like

Hey thank you so much for explaining this to me. I totally didn’t understand how to use callFunc properly. I finally narrowed this problem down to my callFunc(s) just being plain wrong and found this post CallFunc don’t work in sequence after delayTime which demonstrates your point as well. The main thing was that I wasn’t passing it a node. I thought I only had to do that for callFuncN which is a function that no longer seems to exist but was shown in the docs I was using which must have been outdated. On a side note I think it might be possible to say cc.callFunc(theMouse.setEnabled(true), theMouse); which I am going to test just for fun. Thanks again.