0

I have a button as a CCMenuItemImage on a menu that I animate to grow and shrink with the code below, however the pauseSchedulerAndActions does not seem to work.

id butActionGrow = [CCScaleTo actionWithDuration:0.8 scale:1.05];
id butActionShrink = [CCScaleTo actionWithDuration:0.8 scale:1.0];
id butActionSeq = [CCSequence actions:butActionGrow, butActionShrink, nil];
[myButton runAction:[CCRepeatForever actionWithAction:butActionSeq]];
[myButton pauseSchedulerAndActions]; //DOES NOT PAUSE ACTION

The animation just continues to run and does not pause. Any thoughts on why it will not pause?

Thanks

EDIT: Note that I need to be able to resume the actions at a later time as well.

EDIT: Based on Karthik Ra's answer below, I came up with the following solution to stop all actions when needed and then when needing to resume the actions, just check to make sure there are no actions already running and start the sequence again:

[myButton runAction:[CCRepeatForever actionWithAction:[CCSequence actions:[CCScaleTo actionWithDuration:0.8 scale:1.05], [CCScaleTo actionWithDuration:0.8 scale:1.0], nil]]];
[myButton stopAllActions];
if ([myButton numberOfRunningActions] == 0) {
    [myButton runAction:[CCRepeatForever actionWithAction:[CCSequence actions:[CCScaleTo actionWithDuration:0.8 scale:1.05], [CCScaleTo actionWithDuration:0.8 scale:1.0], nil]]];
}
jsherk
  • 6,128
  • 8
  • 51
  • 83
  • Have you seen this? http://stackoverflow.com/questions/19056101/cocos2d-actions-and-animations-are-not-paused – uchamp Apr 04 '14 at 05:31
  • I had not seen that. That is good information, although I do not understand what it is saying fully. Are the actions children of the button and and that is why pauseSchedulerAndActions does not work on them? – jsherk Apr 04 '14 at 12:15

1 Answers1

1
try this:

 [myButton stopAllActions];
KARTHIK RA
  • 469
  • 2
  • 8
  • @karthik_ra okay so yes this stops the actions, but how do I restart them again? I need to pause the button animation and then restart it later. I have updated my question. – jsherk Apr 04 '14 at 12:12
  • I accepted this as correct answer as it led me to find a solution which I posted above in my question. – jsherk Apr 04 '14 at 12:44
  • FiniteTimeActions only pause and resume. CCRepeatForever actions(inFiniteTimeActions) cannot pause and resume. – KARTHIK RA Apr 04 '14 at 13:10
  • Okay well that explains why pause does not work! Thanks – jsherk Apr 04 '14 at 18:42