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

        <tfoot id='JhKhH'></tfoot>
      1. <legend id='JhKhH'><style id='JhKhH'><dir id='JhKhH'><q id='JhKhH'></q></dir></style></legend>

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

        在cocos2d中检测精灵上的透明部分?

        时间:2024-04-14
        <tfoot id='Dus4f'></tfoot>

        <legend id='Dus4f'><style id='Dus4f'><dir id='Dus4f'><q id='Dus4f'></q></dir></style></legend>

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

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

                  <tbody id='Dus4f'></tbody>

                  本文介绍了在cocos2d中检测精灵上的透明部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我是 Cocos2d 的初学者.我有一个精灵,我想忽略对该精灵透明区域的触摸.

                  I'm beginner in Cocos2d. I have a sprite, and I want to ignore touch on transparent area of that sprite.

                  我知道这个答案 Cocos2d 2.0 - 忽略对图层/精灵透明区域的触摸,还有这篇很棒的文章 http://www.learn-cocos2d.com/2011/12/fast-pixelperfect-collision-detection-cocos2d-code-1of2/.

                  I'm aware of this answer Cocos2d 2.0 - Ignoring touches to transparent areas of layers/sprites, and also this great article http://www.learn-cocos2d.com/2011/12/fast-pixelperfect-collision-detection-cocos2d-code-1of2/.

                  我能够使其与 KKPixelMaskSprite 一起使用,但仅当从文件中使用 sprite 而不是从批处理节点使用时.每当我使用批处理节点(Sprite 表)来获取 sprite 时,它就会停止工作.

                  I was able to make it work with KKPixelMaskSprite, but only when sprite is used from file, but not from batch node. Whenever I use batch node (Sprite sheet), to get sprite , it stops working.

                  我有不同的精灵,我想用这种方式检测 -> 如果触摸在当前的精灵边界框中,那部分在精灵上是否透明?

                  I have different sprites on each other, and I want detect this way -> if touch is in current sprite bounding box, is that part transparent on sprite or no?

                  P.S.我正在使用 cocos2d 1.0.我现在不想使用任何物理引擎,我只想忽略对精灵透明区域的触摸(使用批处理节点创建).我该怎么做?或者是否有任何工具可以提供帮助?

                  P.S.I'm using cocos2d 1.0. I don't want to use any Physics engine for now, I just want to ignore touches on transparent areas of sprite (that was created using batch node ) .How can I do that? Or might there any tool can be helpfull?

                  非常感谢.

                  推荐答案

                  可以使用 CGMutablePathRef 进行非矩形精灵碰撞检测.

                  You can use CGMutablePathRef to make non-rectangular sprite collision detection.

                  //检查

                      CGPoint loc =[mySprite convertToNodeSpace:touchPoint];
                  
                      if([mySprite isPointInsideMap:loc]) 
                      {
                           //touched inside..
                      }
                  
                  //Add this method in your MySprite class derived from CCSprite.
                  -(bool)isPointInsideMap:(CGPoint)inPoint
                  {
                      if (CGPathContainsPoint(mCollisionPath, NULL, inPoint, NO) ) 
                      {
                          return true;
                      }
                  
                      return false;
                  }
                  

                  ////创建路径

                  CGMutablePathRef  mCollisionPath = CGPathCreateMutable();
                  CGPathMoveToPoint(mCollisionPath,    NULL,  0, 0 );
                  CGPathAddLineToPoint(mCollisionPath, NULL,   11, 82 );
                  CGPathAddLineToPoint(mCollisionPath, NULL,   42, 152 );
                  CGPathAddLineToPoint(mCollisionPath, NULL,   86, 202 );
                  CGPathAddLineToPoint(mCollisionPath, NULL,   169, 13 );
                  CGPathCloseSubpath(mCollisionPath);
                  

                  这篇关于在cocos2d中检测精灵上的透明部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:iOS 图形问题 下一篇:iOS 图像命名约定

                  相关文章

                    <bdo id='OAx7B'></bdo><ul id='OAx7B'></ul>
                • <tfoot id='OAx7B'></tfoot>

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

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

                    <legend id='OAx7B'><style id='OAx7B'><dir id='OAx7B'><q id='OAx7B'></q></dir></style></legend>