cocos2dx 碰撞检测

 //必须 要有float类型的参数
void MainScene::updateFrame(float dt)
{
if (spriteTest != NULL && spriteTest->getBoundingBox().intersectsRect(sprite->getBoundingBox())) {
CCLOG("碰撞了!");
spriteTest->stopAllActions();
spriteTest->removeFromParentAndCleanup(true);
spriteTest = NULL;
}
}
bool MainScene::init()
{
if (!Layer::init()) {
return false; } //创建一个精灵
spriteTest = Sprite::create("1.png");
spriteTest->setPosition(Point(,));
this->addChild(spriteTest); sprite = Sprite::create("1.png");
sprite->setPosition(Point(,));
this->addChild(sprite); MoveBy *by = MoveBy::create(, Vec2(, ));
spriteTest->runAction(by); //帧回调
this->schedule(schedule_selector(MainScene::updateFrame));
return true; }
上一篇:JAVA常用基础知识点[继承,抽象,接口,静态,枚举,反射,泛型,多线程...]


下一篇:20155204 2016-2017-2 《Java程序设计》第6周学习总结