1、首先用Texturepicker合成文件后缀为**.plist和 **.png的文件,很简单详细操作去问度娘
2、创建新的动画函数,用于将图片打包成为动画
第一步,在Helloworld.h文件里面进行方法的声明
private:
cocos2d::CCAnimate* createAnimation();
第二步,在HelloWorld.cpp里面对方法进行定义
cocos2d::CCAnimate* HelloWorld::createAnimation(){
//将图片加载到数据池
CCSpriteFrameCache* zCache = CCSpriteFrameCache::sharedSpriteFrameCache();
zCache->addSpriteFramesWithFile("haipi.plist","haipi.png");
//创建数组,存储所有的动画帧
int frameNum = 10;
CCSpriteFrame* spriteFrame=NULL;
CCArray* frameArray = CCArray::create();
//列表保存所有的CCSpriteFrame对象
for(int i=1;i<frameNum;i++){
//从缓存中获取CCSpriteFrame对象
spriteFrame = zCache->spriteFrameByName(CCString::createWithFormat("haipi_%d.png",i)->getCString());
frameArray->addObject(spriteFrame);
}
//用CCSpriteFrame列表创建动画
CCAnimation* animation = CCAnimation::createWithSpriteFrames(frameArray);
animation->setLoops(-1);
animation->setDelayPerUnit(0.2f);
//将动画打包装成动作
CCAnimate* action = CCAnimate::create(animation);
return action;
}
第三步,在HelloWorld的HelloWorld::init()(初始化方法)里对函数和资源进行加载
/*用小图片创建精灵*/
CCSprite* pBehindPointSprite = CCSprite::create("happy03_1");
pBehindPointSprite->setPosition(ccp(300,200));
this->addChild(pBehindPointSprite,2);
pBehindPointSprite->runAction(createAnimation());
简单三步就可以将动画制作出来了,作为新手,这么详细的步骤也应该可以看得懂吧