The ability to pause and resume the Director within Cocos2D makes it relatively easy to implement a game’s pause and resume button.
Important: Scenes/Nodes doesn't support the CocosNodeOpacity protocol.
Pausing the Game
The director pauses the current scene, and SimpleAudioEngine pauses the background music.
[[CCDirector sharedDirector] stopAnimation];
[[CCDirector sharedDirector] pause];
[[SimpleAudioEngine sharedEngine] pauseBackgroundMusic];
Resuming the Game
The director resumes the current scene, and SimpleAudioEngine resumes the background music.
[[CCDirector sharedDirector] stopAnimation];
[CCDirector sharedDirector] resume];
[[SimpleAudioEngine sharedEngine] resumeBackgroundMusic];
[[CCDirector sharedDirector] startAnimation];
For other unwanted cases, for example, when user got a Mobile Call, user presses on Home button you can do it through Application Life Cycles methods.
To Pause
- (void) applicationDidEnterBackground:(UIApplication *)application
{
[[CCDirector sharedDirector] stopAnimation];
[[SimpleAudioEngine sharedEngine] pauseBackgroundMusic];
[[CCDirector sharedDirector] pause];
}
- (void)applicationWillResignActive:(UIApplication *)application
{
[[CCDirector sharedDirector] stopAnimation];
[[SimpleAudioEngine sharedEngine] pauseBackgroundMusic];
[[CCDirector sharedDirector] pause];
}
To Resume
- (void)applicationDidBecomeActive:(UIApplication *)application
{
[[CCDirector sharedDirector] stopAnimation];
[[CCDirector sharedDirector] resume];
[[SimpleAudioEngine sharedEngine] resumeBackgroundMusic];
[[CCDirector sharedDirector] startAnimation];
}