I have a game scene which has 2 layers as shown below , when the user taps the Pause button am adding a Pause window layer as a child to Status bar layer. Game is in progress so
Add a new layer when the user press the button "pause", a "pause layer" with a button resume, it may resolve your problem but i don't know if it's the right solution.
Maybe this link may help you Cocos2d pause
You can enable and disable touch like this :
Disable touch before pause :
[self setIsTouchEnabled:NO]
Enable again after resume :
[self setIsTouchEnabled:YES]
In cocos2d-x
this->setTouchEnabled(false);
When the director is paused, the touch dispatcher is not paused, it still dispatches all touch events. I implemented game pause/resume with a game state (an integer).
int _state;
- (void) pause{
if(_state == kGameStatePlaying){
_state = kGameStatePaused;
//TODO - pause the game
}
}
- (void) resume{
if(_state == kGameStatePaused){
_state = kGameStatePlaying;
//TODO - resume the game
}
}
- (void) ccTouchesBegan:(NSSet *) tiuches withEvent:(UIEvent *) event{
if(_state != kGameStatePlaying)
return;
//.....
}
Use a game state is very useful in many other cases. In my implementation, I never pause the director when pause the game. Pausing director is the easiest way to pause the game, but if you need to do some animations in the pause layer (eg. animal jumps, text blinks ...), you obviously cannot because the director is paused. The solution is to pause schedulers and actions of all the game actors and the game layer itself. The pause and resume methods should look like (assume that you store all game actor in an array named allActors)
- (void) pause{
if(_state == kGameStatePlaying){
_state = kGameStatePaused;
[self pauseSchedulerAndActions];
[allActors performSelector:@selector(pauseSchedulerAndActions)];
}
}
- (void) resume{
if(_state == kGameStatePaused){
_state = kGameStatePlaying;
[self resumeSchedulerAndActions];
[allActors performSelector:@selector(resumeSchedulerAndActions)];
}
}
Hope this helps :)