帧动画
1.动画的调用
CCAnimation *pAnimation = CPalaceControl::Instance()->InitSimpleAnimation(ANIMATION_TRIBUTE_POSTION, 8, PalaceConfig::ANIMATION_TIME_PER_FRAME, true);
if (NULL == pAnimation)
{
return false;
}
pSpQuan->runAction(CCRepeatForever::actionWithAction(CCAnimate::actionWithAnimation(pAnimation)));
const string CLiFoLogic::ANIMATION_TRIBUTE_POSTION = "FoPosition"; (单个图片名字FoPosition1.png)
static const float ANIMATION_TIME_PER_FRAME= 0.0667f;
2.动画的实现
CCAnimation * CPalaceControl::InitSimpleAnimation(
const string &strFileName, const int &nFramesCount, const float &fTimePerFrame, const bool &bReadWriteble)
{
CCSpriteFrameCache *pCache = CCSpriteFrameCache::sharedSpriteFrameCache();
if (NULL == pCache)
{
return NULL;
}
pCache->addSpriteFramesWithFile(
FileUtil::SelectFilePath(CommonUtil::CreatePlistFileName(strFileName), bReadWriteble).c_str(),
FileUtil::SelectFilePath(CommonUtil::CreateImageFileName(strFileName), bReadWriteble).c_str());
CCMutableArray<CCSpriteFrame *> *pAnimFrames = new CCMutableArray<CCSpriteFrame*>(nFramesCount);
char str[100] = {0};
for(int i = 1; i <= nFramesCount; i++)
{
sprintf(str, (strFileName + "%d.png").c_str(), i);
CCSpriteFrame *pFrame = pCache->spriteFrameByName(str);
pAnimFrames->addObject(pFrame);
}
CCAnimation *pAnimation = CCAnimation::animationWithFrames(pAnimFrames, fTimePerFrame);
pAnimFrames->removeAllObjects(true);
CC_SAFE_DELETE(pAnimFrames)
return pAnimation;
}