| 我之前介绍了cocos2d-x各种动画的创建方式,但是2.0修改了一些方法,又有很多朋友问我怎么创建动画,今天我再介绍下2.0的动画创建方式,希望大家看到了,能够自己学着创建其他方式的动画。 
 一、使用swf创建动画。
 
 1、首先使用TexturePacker工具将swf导出成plist文件。
 
 2、创建动画的方法:
 复制代码CCActionInterval* SAAnimationManager::createRFAnimFormSwf(const char* swfName,int frames){
 
char str1[100] = {0};
 
char str2[100] = {0};
 
CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache();
 
sprintf(str1, "%s.plist", swfName);
 
sprintf(str2, "%s.png", swfName);
 
cache->addSpriteFramesWithFile(str1,str2);
 
CCArray* animFrames = CCArray::create(15);
 
for(int i = 0; i < frames; i++){
 
sprintf(str2, "%s.swf/%04d", swfName,i);
 
CCSpriteFrame *frame = cache->spriteFrameByName(str2);
 
animFrames->addObject(frame);
 
}
 
CCAnimation *animation = CCAnimation::create(animFrames, kDelayPerUnit);
 
cache->removeSpriteFramesFromFile(str1);
 
return CCRepeatForever::create(CCAnimate::create(animation));
 
}
参数介绍: const char* swfName :swf的名字,记住swf的名字最好和plist的名字一样。如果你的swf名字和导出的plist名字不一样,你会发现pilst里面的每一帧的名字是swf的名字,plist是你取的名字,就会有两个不同的名字,这样在加载里面每一帧的时候就注意了名字了。 int frames:swf的帧数。 
 这样就会返回一个永久性的动画,你就可以用一个sprite->runAction()的方式显示这个动作了。 |