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

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

          <bdo id='GkqOi'></bdo><ul id='GkqOi'></ul>
      2. <tfoot id='GkqOi'></tfoot>

        cocos2d sprite 碰撞检测boundingbox

        时间:2024-08-12

          <tbody id='s9r8O'></tbody>

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

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

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

                • <legend id='s9r8O'><style id='s9r8O'><dir id='s9r8O'><q id='s9r8O'></q></dir></style></legend>
                  本文介绍了cocos2d sprite 碰撞检测boundingbox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有 2 个精灵.我使用边界框来检查与 CGRectIntersectsRect 的碰撞.但它不起作用.HBBall 和 HBpaddle 都有一个名为 image 的 CCSprite.

                  I got 2 sprites. I use the boundingbox to check for collision with CGRectIntersectsRect. But it is not working. HBBall and HBpaddle has a CCSprite called image.

                  初始化:

                      ball = [[HBBall alloc] init];
                      ball.position = ccp(150, 50);
                      [self addChild:ball];
                      [update addObject:ball];
                  
                      paddle1 = [[HBPaddle alloc] init];
                      paddle1.position = ccp(50, 160);
                      [self addChild:paddle1];
                  

                  更新:

                  if (CGRectIntersectsRect([paddle1.image boundingBox], [ball.image boundingBox])) 
                      CCLOG(@"ball hit paddle");
                  

                  CGRectIntersectsRect 总是返回 true.有人有想法吗?

                  CGRectIntersectsRect retuns always true. Does anyone have an idea?

                  推荐答案

                  你不能直接传递边界框,因为它是相对于精灵的.您必须像这样传递绝对 CGRect 边界框:

                  you cant pass directly the bounding box, because it's relative to the sprite. You MUST pass the absolute CGRect boundingbox like this:

                  s = CCsprite
                  s.anchorPoint = ccp(0, 0);    
                  CGRect absoluteBox = CGRectMake(s.position.x, s.position.y, [s boundingBox].size.width, [s boundingBox].size.height);
                  

                  进行必要的调整!

                  希望能帮上忙!

                  这篇关于cocos2d sprite 碰撞检测boundingbox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Cocos2d - 设置设备/屏幕方向 下一篇:如何暂停和恢复应用于 ccSprite 的操作?

                  相关文章

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

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

                    <bdo id='r2IHa'></bdo><ul id='r2IHa'></ul>
                  <legend id='r2IHa'><style id='r2IHa'><dir id='r2IHa'><q id='r2IHa'></q></dir></style></legend>