一.用TexturePacker-2.4.5工具做动画(要包含#include "AnimatePacker.h"文件)
1:用TexturePacker-2.4.5工具将序列图加载到大图中生成plist文件加载到项目中
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("quest.plist"),CCTextureCache::sharedTextureCache()->textureForKey("quest.png");
2:AnimatePacker工具的使用
lockSprite->setPosition(ccp(this->getContentSize().width * 0.5f, this->getContentSize().height * 0.5f));
this->addChild(lockSprite, 1);
lockSprite ->runAction(AnimatePacker::getInstance()->getAnimate("portraitAnimiton"));
另外你也可以让这段动画加入动作序列中和其他动画一块执行代码如下:
CCSequence *PotraitSequence = CCSequence::create(deleteLockSprite, AnimatePacker::getInstance()->getAnimate("portraitAnimiton"), afterAnimitionAction, NULL);
lockSprite->runAction(PotraitSequence);
二.普通的序列图动画的创建 这个也是要提前将序列图加载成大图plist加载到资源中
//1:创建帧缓存
CCSpriteFrameCache* pCacheObject = CCSpriteFrameCache::sharedSpriteFrameCache();
CCSize size = CCDirector::sharedDirector()->getWinSize();
//2:创建帧动作的存储数组
CCArray *pSpriteFrameArray=new CCArray();
//3:循环将序列图加载到帧缓存和数组中
for(unsigned int Index = 1; Index <= 32; Index++)
{
CCString *stringName;
if (Index < 10) {
stringName = CCString::createWithFormat("Animation_portrait_locked_000%d.png", Index);
}
else {
stringName = CCString::createWithFormat("Animation_portrait_locked_00%d.png", Index);
}
CCSpriteFrame* pSpriteFrame = pCacheObject->spriteFrameByName(stringName->getCString());
pSpriteFrameArray->addObject(pSpriteFrame);
}
//4:创建一个动画对象
CCAnimation *animationObject = CCAnimation::createWithSpriteFrames(pSpriteFrameArray, 0.05f);
//5:创建执行动画的精灵
CCSprite *pSprite = CCSprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("Animation_portrait_locked_0001.png"));
pSprite->setScale(1.8f);
pSprite->setPosition(ccp(pSprite->getContentSize().width * 0.73f, pSprite->getContentSize().height * 0.72f));
this->addChild(pSprite, 1);
//6:动作序列
CCActionInterval* actionAnimition = CCAnimate::create(animationObject);
CCCallFuncN * deleteLockSprite = CCCallFuncN::create(this, callfuncN_selector(PlayerPortraitSprite::deleteLockSpriteCallBack));
CCCallFuncN * afterAnimitionAction = CCCallFuncN::create(this, callfuncN_selector(PlayerPortraitSprite::afterPlayAnimitionCallBack));
CCSequence *PotraitSequence = CCSequence::create(deleteLockSprite, actionAnimition, afterAnimitionAction, NULL);
pSprite->runAction(PotraitSequence);
//7:释放数组对象
pSpriteFrameArray->release();
}