【问题标题】:How to detect the collision of three sprite in cocos2d-x 2.2?cocos2d-x 2.2中如何检测三个精灵的碰撞?
【发布时间】:2014-06-24 13:17:27
【问题描述】:

我是 cocos2d-x 的新手,我正在实现自己的 Flappy Bird。

现在我正在处理碰撞检测,但我被卡住了。

我将 down_pipe sprite 和 up_pipe sprite 添加到父 sprite 管道,并将父 shift 从右移到左。

但是当我检查碰撞时

if (bird->boundingBox().intersectsRect(pipes->boundingBox()))

它不起作用。

我尝试这种方式:

if (bird->boundingBox().intersectsRect(pipes->getChildByTag(DOWN_PIPE)->boundingBox()) || bird->boundingBox().intersectsRect(pipes->getChildByTag(UP_PIPE)->boundingBox()))

还是不行。

我该如何解决这个问题?有什么建议吗?

【问题讨论】:

  • @RachelGallen 我的问题是我将两个单独的 CCSprite 添加到父 CCSprite,然后我无法通过上面所说的检查碰撞。并且父CCSprite的boundingBox大小始终为{0.0,0.0}且原点发生变化,up_pipe和down_pipe的boundingBox保持不变。
  • 另外,也许您应该为此使用 Box2D 或 Chipmunk?
  • 尝试使用 convertToWorldSpace 函数。或者使用 parent 的位置和大小的 down_pipe 和 up_pie 来创建一个临时 rect。并检查与此的交集。

标签: c++ cocos2d-x cocos2d-x-2.x


【解决方案1】:

你试试这个,

        CCRect target = CCRectMake(pipes->getPosition().x - (pipes->getContentSize().width/2),pipes->getPosition().y - (pipes->getContentSize().height/2),pipes->getContentSize().width,pipes->getContentSize().height);

if (bird->boundingBox().intersectsRect(target))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-04
    • 2013-03-09
    • 1970-01-01
    相关资源
    最近更新 更多