//帧动画的创建
//方式一,通过多张图片来创建
auto sprite1 = Sprite::create("grossini_dance_05.png");
sprite1->setPosition(Vec2(visibleSize.width*0.3, visibleSize.height/2));
this->addChild(sprite1); //创建帧动画序列,名词形式
auto animation = Animation::create();
for (int i=5; i<11; i++)
{
char szName[100] = {0};
sprintf(szName, "grossini_dance_%02d.png", i);
animation->addSpriteFrameWithFile(szName);
}
//设置帧动画属性
animation->setDelayPerUnit(2.0f / 6); //每一帧停留的时间,2秒时间完成6幅图片显示,切记要写成2.0f形式!
animation->setRestoreOriginalFrame(true); //播放完后回到第一帧 auto animate = Animate::create(animation);
sprite1->runAction(RepeatForever::create(animate)); //方式二,通过一张集合的图片来创建
//创建2D纹理
auto texture = Director::getInstance()->getTextureCache()->addImage("dragon_animation.png");
//建立图片帧
auto frame0 = SpriteFrame::createWithTexture(texture, Rect(132*0, 132*0, 132, 132));
auto frame1 = SpriteFrame::createWithTexture(texture, Rect(132*1, 132*0, 132, 132));
auto frame2 = SpriteFrame::createWithTexture(texture, Rect(132*2, 132*0, 132, 132));
auto frame3 = SpriteFrame::createWithTexture(texture, Rect(132*3, 132*0, 132, 132));
auto frame4 = SpriteFrame::createWithTexture(texture, Rect(132*0, 132*1, 132, 132));
auto frame5 = SpriteFrame::createWithTexture(texture, Rect(132*1, 132*1, 132, 132)); auto sprite2 = Sprite::createWithSpriteFrame(frame0);
sprite2->setPosition(Vec2(visibleSize.width/2, visibleSize.height/2));
this->addChild(sprite2); //保存图片帧
//Vector<cocos2d::AnimationFrame *> array;
Vector<cocos2d::SpriteFrame *> array;
array.pushBack(frame0);
array.pushBack(frame1);
array.pushBack(frame2);
array.pushBack(frame3);
array.pushBack(frame4);
array.pushBack(frame5); auto animation2 = Animation::createWithSpriteFrames(array, 0.2f); //此处createWithSpriteFrames()函数确实每帧间隔时间参数,需自行加上去!!!
sprite2->runAction(RepeatForever::create(Animate::create(animation2))); //方式三,通过.plist 文件来创建
auto cache = SpriteFrameCache::getInstance();
cache->addSpriteFramesWithFile("animate.plist"); auto sprite3 = Sprite::createWithSpriteFrameName("grossini_dance_05.png");
sprite3->setPosition(Vec2(visibleSize.width*0.7, visibleSize.height/2));
this->addChild(sprite3); Vector<cocos2d::SpriteFrame *> arr;
char str[100] = {0};
for (int i=1; i<15; i++)
{
sprintf(str, "grossini_dance_%02d.png", i);
auto frame_2 = cache->SpriteFrameCache::getInstance()->getSpriteFrameByName(str); //3.2版本有改变
arr.pushBack(frame_2);
} auto animation3 = Animation::createWithSpriteFrames(arr, 0.2f); //此处也不要忘记加上时间间隔参数
sprite3->runAction(RepeatForever::create(Animate::create(animation3))); return true;

  

最新文章

  1. C++的性能C#的产能?! - .Net Native 系列四:性能测试方法(PerfView)
  2. CentOS 6.6 升级GCC G++ (当前最新版本为v6.1.0) (完整)
  3. 将做好的py文件打包成模块,供别人安装调用
  4. Yii源码阅读笔记(三十二)
  5. java关键字之final
  6. mysql A表部分记录复制到B表
  7. css中table tr:nth-child(even)改变tr背景颜色: IE7,8无效
  8. 救援行动(save) (BFS)
  9. 使用ngin的静态文件下载
  10. Error (10028): Can&#39;t resolve multiple constant drivers for net &quot;out2&quot; at shiyan.v(14)解决办法
  11. OSI七层模型具体解释
  12. 关于Intent的七大属性
  13. 配置hive元数据库mysql时候出现 Unable to find the JDBC database jar on host : master
  14. 基于 JVMTI 实现 Java 线程的监控(转)
  15. iherb账户
  16. JMS连接WMQ及收发消息
  17. 类的构造器-init和new
  18. css样式问题解决
  19. loadrunner&#160;脚本优化-加密与解密
  20. Oracle存储过程的调试

热门文章

  1. hdu 1847 Good Luck in CET-4 Everybody!(sg)
  2. RK30SDK开发板驱动分析(二):DDR频率配置
  3. xss攻击的分类
  4. xml获取指定节点的路径
  5. hdu-2544-最短路(Floyd算法模板)
  6. java-10异常处理动手动脑
  7. LeetCode 333. Largest BST Subtree
  8. 1.react的基础知识
  9. GWT中自定义你的&quot;cell&quot;
  10. Jconsole 测试.