1. <small id='J3v3r'></small><noframes id='J3v3r'>

      <legend id='J3v3r'><style id='J3v3r'><dir id='J3v3r'><q id='J3v3r'></q></dir></style></legend>
      • <bdo id='J3v3r'></bdo><ul id='J3v3r'></ul>
      <i id='J3v3r'><tr id='J3v3r'><dt id='J3v3r'><q id='J3v3r'><span id='J3v3r'><b id='J3v3r'><form id='J3v3r'><ins id='J3v3r'></ins><ul id='J3v3r'></ul><sub id='J3v3r'></sub></form><legend id='J3v3r'></legend><bdo id='J3v3r'><pre id='J3v3r'><center id='J3v3r'></center></pre></bdo></b><th id='J3v3r'></th></span></q></dt></tr></i><div id='J3v3r'><tfoot id='J3v3r'></tfoot><dl id='J3v3r'><fieldset id='J3v3r'></fieldset></dl></div>
      <tfoot id='J3v3r'></tfoot>

      恢复游戏 cocos2d

      时间:2024-08-12

        <i id='BrAVt'><tr id='BrAVt'><dt id='BrAVt'><q id='BrAVt'><span id='BrAVt'><b id='BrAVt'><form id='BrAVt'><ins id='BrAVt'></ins><ul id='BrAVt'></ul><sub id='BrAVt'></sub></form><legend id='BrAVt'></legend><bdo id='BrAVt'><pre id='BrAVt'><center id='BrAVt'></center></pre></bdo></b><th id='BrAVt'></th></span></q></dt></tr></i><div id='BrAVt'><tfoot id='BrAVt'></tfoot><dl id='BrAVt'><fieldset id='BrAVt'></fieldset></dl></div>
          <tbody id='BrAVt'></tbody>
          <bdo id='BrAVt'></bdo><ul id='BrAVt'></ul>

            • <small id='BrAVt'></small><noframes id='BrAVt'>

              <tfoot id='BrAVt'></tfoot>

            • <legend id='BrAVt'><style id='BrAVt'><dir id='BrAVt'><q id='BrAVt'></q></dir></style></legend>

                本文介绍了恢复游戏 cocos2d的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我使用下面的代码来处理我的游戏中的暂停和恢复按钮

                I used he code below to handle pause and resume buttons in my game

                暂停:

                -(void)pauseTapped{
                ...    
                    [[SimpleAudioEngine sharedEngine] pauseBackgroundMusic];
                    [[CCDirector sharedDirector] pause];
                ...
                }
                

                继续:

                -(void)resumeGame: (id)sender {
                ...
                    [self removeChild:pauseMenu cleanup:YES];
                
                    [[SimpleAudioEngine sharedEngine] resumeBackgroundMusic];
                    [[CCDirector sharedDirector] resume];
                ...
                }
                

                问题是如果使用点击暂停然后进入后台(点击主页按钮)模式当他返回时,游戏自动恢复,暂停菜单仍然存在

                The problem is if the used click pause then enterBackground (click Home button) mode when he returns, the game automatically resume and the pause menu still exist

                任何想法都会很棒

                更新:

                AppDelegate 代码:

                the AppDelegate code:

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

                谢谢

                推荐答案

                您应该向您的应用程序委托添加一个属性,该属性将跟踪暂停是由用户点击暂停按钮还是自动引起的.

                You should add a property to your app delegate that will keep track if pause was caused by user tapping pause button or automatically.

                在 YourAppDelegate.h 中:

                Inside YourAppDelegate.h:

                @property (nonatomic) BOOL userPaused;
                

                在 YourAppDelegate.h 中:

                And inside YourAppDelegate.h:

                @synthesize userPaused;
                

                然后在场景的 pause 方法中,添加:

                Then inside your scene's pause method, add:

                YourAppDelegate *appDelegate = (YourAppDelegate *)[[UIApplication sharedApplication] delegate];
                appDelegate.userPaused = YES;
                

                在场景的 resume 方法中,添加:

                And inside your scene's resume method, add:

                YourAppDelegate *appDelegate = (YourAppDelegate *)[[UIApplication sharedApplication] delegate];
                appDelegate.userPaused = NO;
                

                现在您可以编辑您的应用委托的 -applicationWillResignActive: 方法以仅在 userPaused 未设置为 YES 时恢复.

                Now you can edit your app delegate's -applicationWillResignActive: method to only resume if userPaused is not set to YES.

                - (void)applicationDidBecomeActive:(UIApplication *)application {
                    if (!self.userPaused) {
                        [[CCDirector sharedDirector] resume];
                    }
                }
                

                这篇关于恢复游戏 cocos2d的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:突出显示朗读文本(在 iPhone 的故事书类型应用程序中) 下一篇:Cocos2d - 如何检查不同层中对象之间的交集

                相关文章

                  <bdo id='xSN4P'></bdo><ul id='xSN4P'></ul>

                1. <i id='xSN4P'><tr id='xSN4P'><dt id='xSN4P'><q id='xSN4P'><span id='xSN4P'><b id='xSN4P'><form id='xSN4P'><ins id='xSN4P'></ins><ul id='xSN4P'></ul><sub id='xSN4P'></sub></form><legend id='xSN4P'></legend><bdo id='xSN4P'><pre id='xSN4P'><center id='xSN4P'></center></pre></bdo></b><th id='xSN4P'></th></span></q></dt></tr></i><div id='xSN4P'><tfoot id='xSN4P'></tfoot><dl id='xSN4P'><fieldset id='xSN4P'></fieldset></dl></div>
                  <legend id='xSN4P'><style id='xSN4P'><dir id='xSN4P'><q id='xSN4P'></q></dir></style></legend>

                    <tfoot id='xSN4P'></tfoot>

                    <small id='xSN4P'></small><noframes id='xSN4P'>