0

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?

SundayMonday
  • 19,147
  • 29
  • 100
  • 154

2 Answers2

2

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.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
0

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

Sebastián Castro
  • 1,408
  • 10
  • 28
  • +1 I tried this and had the same problem. Can you point me to some sample code perhaps? – SundayMonday Oct 16 '12 at 19:29
  • 2
    CCSpawn doesn't allow you to run two actions at the same time any more than running two actions one after the other. It creates new actions and has the same effect as SundayMonday's code sample. – CodeSmile Oct 16 '12 at 20:51