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

  • <legend id='xh966'><style id='xh966'><dir id='xh966'><q id='xh966'></q></dir></style></legend>
  • <tfoot id='xh966'></tfoot>

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

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

        Cocos2d 引擎 - 暂停,恢复

        Cocos2d Engine - Pause , resume(Cocos2d 引擎 - 暂停,恢复)
      1. <tfoot id='7p7v0'></tfoot>

        <small id='7p7v0'></small><noframes id='7p7v0'>

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

                <bdo id='7p7v0'></bdo><ul id='7p7v0'></ul>
                1. <legend id='7p7v0'><style id='7p7v0'><dir id='7p7v0'><q id='7p7v0'></q></dir></style></legend>
                  本文介绍了Cocos2d 引擎 - 暂停,恢复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个游戏场景,它有 2 个图层,如下所示,当用户点击暂停按钮时,我将暂停窗口图层作为子图层添加到状态栏图层.游戏正在进行中,所以到目前为止,我实现的是将一个精灵加载到我的游戏层中,并将精灵移动到用户触摸的任何位置.

                  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 till now what I have implemented was loaded a sprite into my Game layer and moving the sprite to the location wherever the user touches.

                  就游戏层"上的触摸处理而言,一切正常,直到用户点击暂停按钮,问题是游戏层"触摸即使在调用 [[CCDirector sharedDirector] pause] 后仍处于活动状态.我仍然可以在暂停模式下在屏幕上移动我的播放器.

                  As far as touch handling on "game layer" goes, everything works perfect until the user taps pause button , the problem am getting is "Game layer" touch is active even after calling [[CCDirector sharedDirector] pause]. Am still able to move my player around the screen in pause mode.

                  请说明 Director pause 和 Touch 之间的关系是什么?

                  Please clarify what is the relation between Director pause and Touch?

                  场景:游戏场景有 2 个孩子

                  - GameScene
                     - Status Bar Layer #1
                       - Pause Button
                          Tap 
                          {
                             [[CCDirector sharedDirector] pause]
                             Add pause Window to Status bar layer;
                          } 
                       - Score Label
                       - Life Status icon
                  
                     - Game Layer #2
                  

                  图层:暂停 CCLayer

                  - PauseGameLayer
                    - Resume Button   
                       Tap 
                       {
                           Remove this layer from parent
                           [[CCDirector sharedDirector] resume];
                       }
                    - Restart Level
                    - Main menu
                  

                  推荐答案

                  director 暂停时,touch dispatcher 并没有暂停,它仍然会派发所有的 touch 事件.我使用游戏状态(整数)实现了游戏暂停/恢复.

                  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;
                     //.....
                  }
                  

                  在许多其他情况下,使用游戏状态非常有用.在我的实现中,我在暂停游戏时从不暂停导演.暂停导演是暂停游戏最简单的方法,但是如果你需要在暂停层做一些动画(例如动物跳跃,文字闪烁......),你显然不能,因为导演被暂停了.解决方案是暂停所有游戏参与者和游戏层本身的调度程序和操作.pause 和 resume 方法应如下所示(假设您将所有游戏 Actor 存储在名为 allActors 的数组中)

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

                  希望这会有所帮助:)

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

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)
                  Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)
                  Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))
                  Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)
                  How to convert 32 bit PNG to RGB565?(如何将 32 位 PNG 转换为 RGB565?)
                  Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)
                  • <legend id='XSuVQ'><style id='XSuVQ'><dir id='XSuVQ'><q id='XSuVQ'></q></dir></style></legend>

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

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

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