首页 > 其他 > 详细

cocos2dx 碰撞检测

时间:2016-01-01 21:05:36      阅读:312      评论:0      收藏:0      [点我收藏+]
 1 //必须 要有float类型的参数
 2 void MainScene::updateFrame(float dt)
 3 {
 4     if (spriteTest != NULL && spriteTest->getBoundingBox().intersectsRect(sprite->getBoundingBox())) {
 5         CCLOG("碰撞了!");
 6         spriteTest->stopAllActions();
 7         spriteTest->removeFromParentAndCleanup(true);
 8         spriteTest = NULL;
 9     }
10 }
11 bool MainScene::init()
12 {
13     if (!Layer::init()) {
14         return false;
15        
16     }
17     
18    //创建一个精灵
19     spriteTest = Sprite::create("1.png");
20     spriteTest->setPosition(Point(40,300));
21     this->addChild(spriteTest);
22     
23     sprite = Sprite::create("1.png");
24     sprite->setPosition(Point(800,300));
25     this->addChild(sprite);
26     
27     MoveBy *by = MoveBy::create(4, Vec2(1136, 0));
28     spriteTest->runAction(by);
29     
30     //帧回调
31     this->schedule(schedule_selector(MainScene::updateFrame));
32     return true;
33     
34 }

 

cocos2dx 碰撞检测

原文:http://www.cnblogs.com/wanyongjian/p/5093667.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!