2013-10-24 87 views
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"); 
} 

任何人給我的想法來解決上述問題?

回答

1

可以使用獲得的炸彈RECT:

CCRect bomb11Rect = bomb.boundingBox 

然後檢查觸摸這個矩形內使用:

CGRectContainsPoint(bomb11Rect, point)