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 }
原文:http://www.cnblogs.com/wanyongjian/p/5093667.html