创建动画最简单的方式,帧动画。
//第一张图
CCSprite* sprite = CCSprite::create("s_1.png");
CCAnimation* animation = CCAnimation::create();
for( int i=1;i<5;i++)
{
char szName[100] = {0};
sprintf(szName, "s_%d.png", i);
animation->addSpriteFrameWithFileName(szName); //加载动画的帧
}
animation->setDelayPerUnit(0.25f);
animation->setRestoreOriginalFrame(true);
animation->setLoops(10); //动画循环10次
CCAnimate *animate = CCAnimate::create(animation);
// sprite->runAction(CCSequence::create(animate, animate->reverse(), NULL)); //这里是循环多少次
sprite->runAction(CCRepeatForever::create(dynamic_cast<CCActionInterval *>(CCSequence::create(animate, animate->reverse(), NULL))));