cocos2d-x中矩形的碰撞检测(2)
来源:未知 责任编辑:责任编辑 发表时间:2013-12-06 08:43 点击:次
p>
p> }else if(x1-w1*0.5>x2+w2*0.5){
p> return false;
p>
p> }else if(y1+h1*0.5
p> return false;
p>
p> }else if(y1-h1*0.5>y2+h2*0.5){
p> return false;
p>
p> }
p> return true;
p>}
p>
p>
p>bool HelloWorld::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent){
p> CCSprite* sp1 =(CCSprite*)this->getChildByTag(921);
p> sp1->setPosition(pTouch->getLocation());
p>
p> return true;
p>}
p>
p>void HelloWorld::ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent){
p>
p> CCSprite* sp1 =(CCSprite*)this->getChildByTag(921);
p> sp1->setPosition(pTouch->getLocation());
p>
p> CCSprite*sp2 =(CCSprite*)this->getChildByTag(922);
p>
p> CCLabelTTF* pLabel = (CCLabelTTF*)this->getChildByTag(900);
p>
p>// //利用自定义判断矩形碰撞函数
p>// if(this->isRectCollision(
p>// CCRectMake(sp1->getPositionX(), sp1->getPositionY(), sp1->getContentSize().width, sp1->getContentSize().height),
p>// CCRectMake(sp2->getPositionX(), sp2->getPositionY(), sp2->getContentSize().width, sp2->getContentSize().height))){
p>// pLabel->setString("碰撞拉!");
p>// }else{
p>// pLabel->setString("~还没有碰撞~");
p>// }
p>
p> //利用intersectsRect函数检测碰撞
p> if(sp1->boundingBox().intersectsRect(sp2->boundingBox())){
p> pLabel->setString("碰撞拉!");
p> }else{
p> pLabel->setString("~还米有碰撞~");
p> }
p>}
p>
p>void HelloWorld::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent){
p>
p>
p>}
p>
p>void HelloWorld::onEnter(){
p> CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, 0, false);
p> CCLayer::onEnter();
p>}
p>
p>void HelloWorld::onExit(){
p> CCDirector::sharedDirector()->getTouchDispatcher()->removeDelegate(this);
p> CCLayer::onExit();
p>}
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>