Question

I want to stop an action once my sprite gets to a certain rotation. For example:

CCAction *rotateUp = [CCRotateTo actionWithDuration:0.3 angle:-35];
[player runAction:rotateUp];

if (player.rotation == -35) {
    [player stopAction:rotateUp];
    [player runAction:[CCRotateTo actionWithDuration:0.5 angle:65]];
}

Once the player gets to the max rotation I want it to run a different action. But this isn't working. What can I do instead?

Was it helpful?

Solution

You cannot get Action output immediately. So it's good to give completion callback for that.

for ex. (in c++)

   CCAction *rotateUp = CCRotateTo::create(0.3f, -35f);
   CCCallFuncN *pCall = CCCallFuncN::create(callfunc_selector(<#_SELECTOR#>));

  player->runAction(CCSequence::create(rotateUp, pCall, NULL));

Here SELECTOR specified get called when rotation action gets completed. Just convert it in Obj C and try.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top