我使用下面的代码来处理游戏中的暂停和恢复按钮。
停顿:
-(void)pauseTapped{
...
[[SimpleAudioEngine sharedEngine] pauseBackgroundMusic];
[[CCDirector sharedDirector] pause];
...
}恢复工作:
-(void)resumeGame: (id)sender {
...
[self removeChild:pauseMenu cleanup:YES];
[[SimpleAudioEngine sharedEngine] resumeBackgroundMusic];
[[CCDirector sharedDirector] resume];
...
}问题是,如果他返回时使用的单击暂停然后单击enterBackground (单击主页按钮)模式,游戏将自动恢复,暂停菜单仍然存在
任何想法都会很好
更新:
AppDelegate代码:
- (void)applicationWillResignActive:(UIApplication *)application {
[[CCDirector sharedDirector] pause];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
[[CCDirector sharedDirector] resume];
}
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
[[CCDirector sharedDirector] purgeCachedData];
}
-(void) applicationDidEnterBackground:(UIApplication*)application {
[[CCDirector sharedDirector] stopAnimation];
}
-(void) applicationWillEnterForeground:(UIApplication*)application {
[[CCDirector sharedDirector] startAnimation];
}
- (void)applicationWillTerminate:(UIApplication *)application {
CCDirector *director = [CCDirector sharedDirector];
[[director openGLView] removeFromSuperview];
[viewController release];
[window release];
[director end];
}
- (void)applicationSignificantTimeChange:(UIApplication *)application {
[[CCDirector sharedDirector] setNextDeltaTimeZero:YES];
}
- (void)dealloc {
[[CCDirector sharedDirector] end];
[window release];
[super dealloc];
}谢谢
发布于 2011-08-27 19:16:29
您应该添加一个属性到您的应用程序委托,这将保持跟踪,如果暂停是由用户点击暂停按钮或自动。
在YourAppDelegate.h里面
@property (nonatomic) BOOL userPaused;在你的内部代表:
@synthesize userPaused;然后在场景的暂停方法中添加:
YourAppDelegate *appDelegate = (YourAppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.userPaused = YES;在场景的简历方法中,添加:
YourAppDelegate *appDelegate = (YourAppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.userPaused = NO;现在,您可以编辑应用程序委托的-applicationWillResignActive:方法,只有当userPaused未设置为YES时才能恢复。
- (void)applicationDidBecomeActive:(UIApplication *)application {
if (!self.userPaused) {
[[CCDirector sharedDirector] resume];
}
}https://stackoverflow.com/questions/7214939
复制相似问题