cocos2d-x 动画之SWF

cocos2d 不支持maya动画个人感觉是一个遗憾!假设能支持maya动画,那游戏资源又要省一大块,美术也要开心一下了,当然,程序猿也应该少不了高兴一下!有试着去弄,但貌似不是那么容易,只能说鄙人才疏学浅!

但是我们还是可以利用flash来实现动画(其实最后还是用序列帧来的),但这样明显的减少了美术的压力!假设现在我们已经拿到了设计好的SWF文件,我们现在要做的就是把它重新打包,用TexturePackerGUI这个软件直接打包出.plist和.png图片,但是我要告诉大家一件事,IOS支持的最大图片为2048*2048,所以,动画不能太大,不然就不行了!

打包完了之后,把.plist和.png放到工程资源文件下。

最后,把调用接口给大家

//-----------------------------------------------
 //通过SWF文件进行动画编辑
 //m_sprite 需要执行动画的精灵
 //swfName SWF文件名称
 //frames 动画总共帧数
 //totalFrames 动画总共执行多少帧,如果大于frames动画总共帧数,则表示动画执行完一次后需要休息一段时间后继续执行(用于循环动画播放)
 //loops 循环次数 -1 无限循环
 //delay 动画执行快慢
 //cleanUp 用于执行一次的动画,执行完了clean掉动画
 //totalFrames 实际需要播放的帧数,(totalFrames-frames)重复播放最后一帧 达到延时播放
  //-----------------------------------------------
 void AnimationForSWF::createDelayAnimFormSwf(CCSprite *m_sprite,const char* swfName,int frames,int totalFrames,int loops,float delay,bool cleanUp)
 {
	 assert(m_sprite!=NULL);
	 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::createWithCapacity(frames);

	 for(int i = 0; i < totalFrames; i++)
	 {
		 if(i>=frames)
			 sprintf(str2, "%s/%04d", swfName,frames-1);
		 else
			 sprintf(str2, "%s/%04d", swfName,i);

		 CCSpriteFrame *frame = cache->spriteFrameByName(str2);

		 animFrames->addObject(frame);

	 }

	 CCAnimation *animation = CCAnimation::createWithSpriteFrames(animFrames, 1/delay);

	 cache->removeSpriteFramesFromFile(str1);
	 animation->setLoops(loops);
	 if(!cleanUp)
		 m_sprite->runAction(CCAnimate::create(animation));
	 else
	 {
		 CCCallFuncN *callFun = CCCallFuncN::create(m_sprite,callfuncN_selector(AnimationForSWF::actionCallBack));
		 m_sprite->runAction(CCSequence::create(CCAnimate::create(animation),callFun,NULL));
	 }
 }
注意,你要看看.plis文件中图片存储的名字是带了wsf还是没带,以上是没带的,带了的话,要在上面图片名字处加上swf。


  有问题请加QQ:497867831 乐意为您效劳

你可能感兴趣的:(cocos2d-x 动画之SWF)