0

当我触摸精灵时,我想在多个精灵中找到精灵(多边形)。

我正在尝试以下代码,但它不起作用。

CCTouchBegan 事件:

CCPoint point = this->convertTouchToNodeSpace(ptouch);

CCRect bomb11Rect = CCRectMake(bomb->getPosition().x ,
                               bomb->getPosition().y ,
                               bomb->getContentSize().width,
                               bomb->getContentSize().height);

CCRect posRect = CCRectMake(point.x ,
                            point.y ,
                            1,
                            1);

if (bomb11Rect.intersectsRect(posRect))
{
    CCLog("Touch the sprite");
}
else
{
    CCLog("Not Touch the sprite");
}

有人给我解决上述问题的想法吗?

4

1 回答 1

1

您可以使用以下方法获得炸弹矩形:

CCRect bomb11Rect = bomb.boundingBox

然后使用以下命令检查它是否在该矩形内:

CGRectContainsPoint(bomb11Rect, point)
于 2013-10-24T18:03:49.143 回答