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());
}
本文介绍了Cocos2d-x游戏开发框架中如何使用GameLayer类的ccTouchBegan方法来实现玩家与游戏角色的触控交互。通过检查触控点是否在角色的边界框内来确定是否触发触控事件。

581

被折叠的 条评论
为什么被折叠?



