3
votes

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'
1
Have you tried [[CCDirector sharedDirector]pause] and [[CCDirector sharedDirector]resume]? - 0xDE4E15B
No I can't do that. Otherwise my pause layer won't be added as a child. - SimplyKiwi
Do you want your scene frozen, or it should be animating while on pause? - 0xDE4E15B
The scene should NOT be frozen, I just want ALL currently animating things in the scene to be paused and resumed successfully. The pauseAllRunningActions does exactly that, but I just don't know the Target it is pausing. And there is no resumeAllRunningActions method. - SimplyKiwi
- (NSSet *) pauseAllRunningActions Pauses all running actions, returning a list of targets whose actions were paused. Hope that helps - 0xDE4E15B

1 Answers

4
votes

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.