<legend id='drGUT'><style id='drGUT'><dir id='drGUT'><q id='drGUT'></q></dir></style></legend>
    1. <small id='drGUT'></small><noframes id='drGUT'>

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

    2. <tfoot id='drGUT'></tfoot>
        • <bdo id='drGUT'></bdo><ul id='drGUT'></ul>

        Cocos2d - 如何检查不同层中对象之间的交集

        Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)
          <tbody id='S7EXE'></tbody>
              <i id='S7EXE'><tr id='S7EXE'><dt id='S7EXE'><q id='S7EXE'><span id='S7EXE'><b id='S7EXE'><form id='S7EXE'><ins id='S7EXE'></ins><ul id='S7EXE'></ul><sub id='S7EXE'></sub></form><legend id='S7EXE'></legend><bdo id='S7EXE'><pre id='S7EXE'><center id='S7EXE'></center></pre></bdo></b><th id='S7EXE'></th></span></q></dt></tr></i><div id='S7EXE'><tfoot id='S7EXE'></tfoot><dl id='S7EXE'><fieldset id='S7EXE'></fieldset></dl></div>
            1. <legend id='S7EXE'><style id='S7EXE'><dir id='S7EXE'><q id='S7EXE'></q></dir></style></legend>
                <bdo id='S7EXE'></bdo><ul id='S7EXE'></ul>
              • <tfoot id='S7EXE'></tfoot>

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

                  本文介绍了Cocos2d - 如何检查不同层中对象之间的交集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我目前正在 Cocos2d 中为 iPhone 开发一个涂鸦跳跃风格的游戏,并设置了一个包含两个不同层的场景 - 游戏对象(平台、收藏品等)和玩家(角色,由玩家控制).

                  I'm currently developing a doodle-jump style game in Cocos2d for iPhone and have a scene set up with two different layers - game objects (platforms, collectables etc...) and player (character, controlled by the player).

                  我将它们放在单独的层中,因为我想在玩家跳跃时向下滚动整个游戏对象层 - 给它一种垂直的、涂鸦跳跃风格的感觉.

                  I have these in separate layers because I want to scroll the entire game objects layer down when the player jumps up - giving it the vertical, doodle-jump style feel.

                  问题在于玩家和平台之间不会发生交集,因为它们位于不同的层.

                  The problem is that intersection between the player and the platforms doesn't occur because they're on different layers.

                  有谁知道如何解决这个问题?有些人提到了 convertToWorldCoords,但我对此一无所知!

                  Does anyone know how this can be solved? Some have mentioned convertToWorldCoords but I'm lost with that!

                  推荐答案

                  是的,先生,convertToWorldCoords!或者,类似的东西——基本上你想了解你的玩家和游戏对象的位置,并且一种方法是将它们全部转换为世界"坐标.或者,您可以将玩家位置/矩形转换为游戏对象的坐标系.

                  Yessir, convertToWorldCoords! Or, something like that -- basically you want to have an understanding of your player and game-object positions in relation to each other, and one way to do that is to transform them all to the "world" coordinates. Alternately you could transform the player position/rectangle to be in your game-objects' coordinate system.

                  想要通过一些 CGRect 交集测试来保持简单吗?用类别扩展 CCNode:

                  Want to keep it simple with just some CGRect intersection tests? Extend CCNode with a category:

                  CCNode+CoordHelpers.h

                  #import "CCNode.h"
                  
                  @interface CCNode (CoordHelpers)
                  - (CGRect) worldBoundingBox;
                  @end
                  

                  CCNode+CoordHelpers.m

                  #import "CCNode+CoordHelpers.h"
                  
                  @implementation CCNode (CoordHelpers)
                  -(CGRect)worldBoundingBox {
                      CGRect rect = CGRectMake(0, 0, contentSize_.width, contentSize_.height);
                      return CGRectApplyAffineTransform(rect, [self nodeToWorldTransform]);
                  }
                  @end
                  

                  那么,对于超简单的 CGRect 碰撞测试:

                  Then, for super simple CGRect collision testing:

                  if(CGRectIntersectsRect([playerObj worldBoundingBox], [otherObj worldBoundingBox])    
                  {/*...do stuff...*
                                  
                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)
                  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 场景重启?)
                  [ios.cocos2d+box2d]how to disable auto-rotation?([ios.cocos2d+box2d]如何禁用自动旋转?)
                    <tbody id='QhrOF'></tbody>

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

                  <tfoot id='QhrOF'></tfoot>
                        <bdo id='QhrOF'></bdo><ul id='QhrOF'></ul>

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