//加载动画
auto animation = Animation::create();
animation->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("hero_blowup_n1.png"));
animation->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("hero_blowup_n2.png"));
animation->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("hero_blowup_n3.png"));
animation->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("hero_blowup_n4.png"));
animation->setDelayPerUnit(0.2);
animation->setRestoreOriginalFrame(true);
auto blowUp = Animate::create(animation);
//爆炸完后结束游戏
auto gameoverCall = CallFunc::create([this]() {
//log("call gameover!");
removeFromParent();
GameScene::sharedGameLayer()->gameover();
});
this->runAction(Sequence::create(blowUp, gameoverCall, nullptr));
1,
CCSpriteFrame:精灵帧。相对于动画产生的,就是一张纹理图片。
CCAnimationFrame:动画帧。由精灵帧和间隔帧数组成,是动画CCAnimation中的一帧。
CCSpriteFrameCache:精灵帧缓冲。用于存放精灵帧CCSpriteFrame的缓冲池。
CCAnimationCache:动画缓冲。用于存放动画CCAnimation的缓冲池。
delayPerUnit: 单位帧间隔。连续两个动画帧之间的间隔。
delayUnits: 间隔帧数。当前动画帧到下一个动画帧需要等待的单位帧间隔的个数。
setRestoreOriginalFrame:动画结束时,是否还原为第一帧。
(2)SpriteFrameCache、AnimationCache 中获得、释放单例对象的方法:
cocos2dx中的基本动画是由CCAnimation和CCAnimate两个类的配合而完成的。