TexturePacker下载地址:http://www.codeandweb.com/texturepacker
TexturePacker的使用
点击Add Sprites按钮添加动画帧
点击publish生成plist文件与打包图片
把生成的plist文件与png文件添加到工程的资源文件目录
帧动画效果的实现
//动画帧效果
//1.创建动画帧序列
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("skill/skill26.plist","skill/skill26.png");
CCArray* frames = CCArray::createWithCapacity(18);//初始化容量为帧数
CCSpriteFrame* frame;
for (int i=1; i<=18; ++i)
{
if(i<10){
//name为未打包图片时的图片原名称
frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(CCString::createWithFormat("skill26-0%d.png",i)->getCString());
}
else{
frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(CCString::createWithFormat("skill26-%d.png",i)->getCString());
}
frames->addObject(frame);
}
//2.根据动画帧序列创建动画(第二个参数为时间间隔)
CCAnimation* pAnimSkill44 = CCAnimation::createWithSpriteFrames(frames,0.2f);
//3.根据动画创建动作
CCAnimate* pSkill44 = CCAnimate::create(pAnimSkill44);
//4.让精灵执行该动作
CCSprite* pSprite = CCSprite::create();
pSprite->setPosition(ccp(visibleSize.width/2, visibleSize.height/2));
this->addChild(pSprite,1);
pSprite->runAction(CCRepeatForever::create(pSkill44));