首页 > 其他 > 详细

创建帧动画

时间:2017-01-09 12:57:33      阅读:174      评论:0      收藏:0      [点我收藏+]
  1. include cocos2d.h
  2. USING_NS_CC;
  3. class ActionTool
  4. {
  1. public:
  1. //声明
  2. //不需要知道图片数量 iloops:循环次数;delay:时间间隔
  3. static Animate * animationWitheFrameName(const char *frameName,int iloops,float delay);
  4. //知道图片数量 num:图片数量 ;
  5. static Animate * animationWitheFameAndNum(const char *frameName,int num, float delay);
  6. };
  7. //定义
  8. #include "ActionTool.h"
  9. Antimate*ActionTool:animationWithFrameName(cosnt char *each_name,int iloops,float delay)
  10. {
  11. SpriteFrame 8frame=NULL;
  12. Aniameion * animation =Animation::create();
  13. int index=1;
  14. do
  15. {
  16. String *name =String::createWithFormat("%s%d",each_name,index++);
  17. frame =SpriteFrameCache::getinstance()->getSpriteFrameByName(name->getCString());
  18. if(fame=NULL)
  19. {
  20. break;
  21. }
  22. animation->addSpriteFrame(frame);
  23. }while(true);
  24. animation->setDelayPerUnit(delay);
  25. animation->setRestoreOriginalFrame(true);
  26. Animate * animate=Animate::create(animation);
  27. return animate;
  28. }
  29. //知道图片数量
  30. Animate * animationWitheFameAndNum(const char *frameName,int num, float delay)
  31. {
  32. SpriteFrame 8frame=NULL;
  33. Aniameion * animation =Animation::create();
  34. for(int index=1;index<num;num++)
  35. {
  36. String *name =String::createWithFormat("%s%d",frameName,index++);
  37. frame =SpriteFrameCache::getinstance()->getSpriteFrameByName(name->getCString());
  38. }
  39. animation->setDelayPerUnit(delay);
  40. animation->setRestoreOriginalFrame(true);
  41. Animate * animate=Animate::create(animation);
  42. return animate;
  43. //方法二
  44. /*Vector<SpriteFrame*>animFrames;
  45. char str20[];
  46. for(int k=1;k<framecount;k++)
  47. {
  48. sprintf(str,"%s%d",frameName,k);
  49. SpriteFrame *frame =SpriteFrameCache::getInstance()->spriteFrameByName(str);
  50. animFrames.pushBack(frame);}
  51. return Animate::create(Animation::crateWithSpriteFrames(animaFrames,delay));*/
  52. return aniamte;
  53. }





创建帧动画

原文:http://www.cnblogs.com/feizuzu/p/f2f02299ae100c52b95d9f2e8136a900.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!