Cocos2D ignoring a CCAction

240 views Asked by At

I'm trying to run two CCMoveTo actions on my sprite like this:

[mySprite runAction:moveUp];
[mySprite runAction:moveRight];

I know that I can combine this motion into a single CCMoveTo however having them separate has some benefits (for example I can reverse the x or y motion independently).

Unfortunately moveUp is totally ignored. Any ideas why?

2

There are 2 answers

0
CodeSmile On BEST ANSWER

You can't run more than one CCMoveTo on the same node. Additional actions of the same type completely override any previous actions' results. The same is true for running two CCRotate*, CCScale* etc actions.

If you want to be able to reverse direction, or in general be flexible about movement, then don't use CCMove* actions at all. They were not designed for gameplay purposes.

Instead, use a scheduled update and manually update position based on velocity.

2
Sebastián Castro On

Use the CCSpawn action, it allows you to run two actions at the same time http://www.cocos2d-iphone.org/api-ref/2.0.0/interface_c_c_spawn.html