在ccTouchesBegan 用;boundingBox 判断是不是在操作英雄

来源:互联网 发布:java编程工具排行榜 编辑:程序博客网 时间:2024/04/27 20:42

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());}



原创粉丝点击