I have a game with animation. In game scene, I use the method below to pause my game (it works perfectly, because the game is paused when the users taps on any point of the iOS device):
-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch=[touches anyObject];
CGPoint locationOfTouch=[self convertTouchToNodeSpace: touch];
CGRect rectOfScreen=CGRectMake(0, 0, screenSize.width, screenSize.height);
if (CGRectContainsPoint(rectOfScreen, locationOfTouch))
{
[[CCDirector sharedDirector] replaceScene:[PauseScene scene]];
[self unschedule:@selector(spawnEnemies:)];
[self unschedule:@selector(checkCollisionOfEnemyWithBullet:)];
[self unschedule:@selector(update:)];
[self unschedule:@selector(isJoystickActivated:)];
[self unschedule:@selector(checkHasGameEnded:)];
[[CCDirector sharedDirector] pause];
}
}
To implement resume action, I'v created PauseLayer:CCLayer, where I've implemented the following method to resume the game:
-(void) continueGame:(id)sender
{
[[CCDirector sharedDirector] resume];
[[CCDirector sharedDirector] replaceScene:[GameSceneLayer scene]];
//[self resumeSchedulerAndActions];
}
Here is the code, how I envoke the method above:
CCMenuItemFont* continue_game=[CCMenuItemFont itemWithString:@"continue game" target:self selector:@selector(continueGame:)];
But, when I select continue game, the game start from the blank point: every game state, every game character will be new. How can I resume my game from the intial point where it was paused by user? Thank you!