Search code examples
rotationspritecocos2d-xcocos2d-x-3.0

2 simultaneous rotate actions


Is there a way to run 2 rotate actions on a sprite at the same time? I have a boat sprite and an oar sprite on the screen, and the oar sprite naturally rotates back and forth. I used a repeat forever action with a sequence of actions to have the oar sprite rotate back and forth through a 90 degree range. I then allow the user to rotate the boat.

I want the oar to continue its own rotation but also to rotate with the boat so that the oar doesn't look misplaced. When I have the boat rotate I create another action to rotate the oar even more and then it doesn't work. The oar just continues with its original action. Any help would be appreciated.

RotateBy * r11 = RotateBy::create(1.95f, 90);
RotateBy * r12 = RotateBy::create(1.95f, -90);

Sequence * s1 = Sequence::create(r11, r12, NULL);

RepeatForever * r1 = RepeatForever::create(s1);

oarSprite->runAction(r1);

Later on I have this in another method:

RotateBy * r = RotateBy::create(.1, boatSprite->getRotation());

The purpose of the last RotateBy action is to get the oar to rotate in relation to the boat.


Solution

  • Just make the oar child of the boat. So oar will rotate with boat rotate action and the oars own.