我有一个动画游戏。在游戏场景中,我使用下面的方法来暂停我的游戏(效果很好,因为当用户点击 iOS 设备的任意一点时,游戏就会暂停):
-(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];
}
}
为了实现恢复动作,我创建了 PauseLayer:CCLayer,在这里我实现了以下方法来恢复游戏:
-(void) continueGame:(id)sender
{
[[CCDirector sharedDirector] resume];
[[CCDirector sharedDirector] replaceScene:[GameSceneLayer scene]];
//[self resumeSchedulerAndActions];
}
这是代码,我如何调用上面的方法:
CCMenuItemFont* continue_game=[CCMenuItemFont itemWithString:@"continue game" target:self selector:@selector(continueGame:)];
但是,当我选择继续游戏时,游戏从空白点开始:每个游戏状态,每个游戏角色都是新的。如何从用户暂停的初始点恢复我的游戏?谢谢!