Cocos2d-x by Example Beginner's Guide,第3章
在GameLayer.ccp中
GameLayer::ccTouchBegan()中
for (int p = 0; p < 2; p++) {
player = (GameSprite *) _players->objectAtIndex(p);
if (player->boundingBox().containsPoint(tap)) {
player->setTouch(touch);
}
}
其中的boundingBox方法可以,确实玩家是否在操作英雄,见boundingBox()方法。
CCRect CCNode::boundingBox()
{
CCRect rect = CCRectMake(0, 0, m_obContentSize.width, m_obContentSize.height);
return CCRectApplyAffineTransform(rect, nodeToParentTransform());
}