Search code examples
ioscocos2d-iphonetargetresumeonpause

Cocos2D pauseAllRunningActions?


I am having a hard time resuming animations in my Cocos2D app. I add a CCSprite as a child to a CCSpriteBatchNode and it goes off on an animation.

So when I click the pause button I do this:

[[[CCDirector sharedDirector] actionManager] pauseAllRunningActions];

Now in the docs they say to use:

[[[CCDirector sharedDirector] actionManager] resumeTargets:];

However, I have tried every possible target including the sprite itself, the batchnode, self (CCLayer), and the current CCScene and nothing has worked.

Is there some sort of way to resume ALL Targets?

Edit: I declared an NSSet in a Singleton and I do this:

[Singleton sharedSingleton].pauseTargets = [[[CCDirector sharedDirector] actionManager] pauseAllRunningActions];
[[[CCDirector sharedDirector] actionManager] pauseAllRunningActions];

Then to resume I do:

[[[CCDirector sharedDirector] actionManager] resumeTargets:[Singleton sharedSingleton].pauseTargets];

But I get a crash:

2012-08-29 18:40:05.433 App[34872:707] -[__NSMallocBlock__ countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x1e075a40
2012-08-29 18:40:05.434 App[34872:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSMallocBlock__ countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x1e075a40'

Solution

  • Stores paused targets

    NSSet *pausedTargets = [[NSSet alloc] initWithSet:[[[CCDirector sharedDirector] actionManager] pauseAllRunningActions]];
    

    Resumes paused targets

    [[[CCDirector sharedDirector] actionManager] resumeTargets:pausedTargets];
    

    Also don't forget to release pausedTargets after you unpause.