Example of Pause and Resume


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];
}

Example of CCSpawn


The CCSpawn action lets you run several actions at the same time. The duration of the CCSpawn action will be the duration of the longest sub-action. 

Inheritance diagram of CCSpawn:



 id action = [CCSpawn actions:
 [CCOrbitCamera actionWithDuration: duration_/2 radius: 1 deltaRadius:0 angleZ:inAngleZ deltaAngleZ:inDeltaZ angleX:0 deltaAngleX:0],
 [CCScaleTo actionWithDuration:duration_/2 scale:1],
 [CCShow action],
 nil],

 [self runAction:action];