//创建一个跑酷的精灵

 auto sprite = Sprite::create("1.png");

//设置精灵的坐标

sprite->setPosition(Vec2(visibleSize.width/,visibleSize.height/));

//添加到当前层

this->addChild(sprite);

//创建序列帧动画

auto animation = Animation::create();

//设置动画名字数组的长度

char nameSize[] = {};

//动画的循环 12张图片

for (int i =; i<; i++)

{

//循环遍历

sprintf(nameSize, "%d.png",i);

 //添加到序列帧动画

  animation->addSpriteFrameWithFile(nameSize);

}

//设置动画帧的时间间隔

animation->setDelayPerUnit(0.02f);

//设置播放循环 一直播放 为-1

animation->setLoops(-);

//设置动画结束后恢复到第一帧

animation->setRestoreOriginalFrame(true);

//创建动画动作

auto animate = Animate::create(animation);

//播放动画

sprite->runAction(animate);
 //帧动画缓存

auto frameCache = SpriteFrameCache::getInstance();

frameCache02->addSpriteFramesWithFile("1.plist");

//创建一个显示动画的精灵

auto sprite = Sprite::createWithSpriteFrameName("1.png");

//设置动画的坐标

sprite->setPosition(Vec2(visibleSize.width/,visibleSize.height/));

//添加到当前层

this->addChild(sprite);

//
创建一个容器
Vector<SpriteFrame*> vec;

//设置动画名字数组的长度

char name[] = {};

for (int i = ; i<; i++) {

//遍历

sprintf(name, "%d.png",i);

vec.pushBack(frameCache->getSpriteFrameByName(name));

}

//auto animation = Animation::createWithSpriteFrames(vec,0.05f);

//也是可以这么写的。那setDelayPerUnit 这个需要注释掉

auto animation = Animation::createWithSpriteFrames(vec);

//设置动画帧的时间间隔

animation->setDelayPerUnit(0.05f);

//设置播放循环 一直播放 为-1

animation->setLoops(-);

//设置动画结束后恢复到第一帧

animation->setRestoreOriginalFrame(true);

//创建动画动作

auto animate = Animate::create(animation);

//播放动画动作

sprite->runAction(animate);
 //通过一张集合的图片来创建
//创建2D纹理
auto texture = Director::getInstance()->getTextureCache()->addImage("dragon_animation.png");
//建立图片帧
auto frame0 = SpriteFrame::createWithTexture(texture, Rect(*, *, , ));
auto frame1 = SpriteFrame::createWithTexture(texture, Rect(*, *, , ));
auto frame2 = SpriteFrame::createWithTexture(texture, Rect(*, *, , ));
auto frame3 = SpriteFrame::createWithTexture(texture, Rect(*, *, , ));
auto frame4 = SpriteFrame::createWithTexture(texture, Rect(*, *, , ));
auto frame5 = SpriteFrame::createWithTexture(texture, Rect(*, *, , )); auto sprite2 = Sprite::createWithSpriteFrame(frame0);
sprite2->setPosition(Vec2(visibleSize.width/, visibleSize.height/));
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)));

cocos2dx 3.x(实现帧动画(人物动画,跑马灯效果)的几种方法)的更多相关文章

  1. WPF编程,通过【帧】动态更改控件属性的一种方法。

    原文:WPF编程,通过[帧]动态更改控件属性的一种方法. 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net/qq_43307934/article/detail ...

  2. WPF编程,通过Path类型制作沿路径运动的动画一种方法。

    原文:WPF编程,通过Path类型制作沿路径运动的动画一种方法. 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net/qq_43307934/article/de ...

  3. android ViewPager实现 跑马灯切换图片+多种切换动画

    近期在弄个项目.要求有跑马灯效果的图片展示. 网上搜了一堆,都没有完美实现的算了还是自己写吧! 实现原理利用 ViewPager 控件,这个控件本身就支持滑动翻页非常好非常强大好多功能都能用上它.利用 ...

  4. 时光煮雨 Unity3D实现2D人物动画② Unity2D 动画系统&资源效率

    系列目录 [Unity3D基础]让物体动起来①--基于UGUI的鼠标点击移动 [Unity3D基础]让物体动起来②--UGUI鼠标点击逐帧移动 时光煮雨 Unity3D让物体动起来③—UGUI DoT ...

  5. 时光煮雨 Unity3D实现2D人物动画① UGUI&Native2D序列帧动画

    系列目录 [Unity3D基础]让物体动起来①--基于UGUI的鼠标点击移动 [Unity3D基础]让物体动起来②--UGUI鼠标点击逐帧移动 时光煮雨 Unity3D让物体动起来③—UGUI DoT ...

  6. android 帧动画,补间动画,属性动画的简单总结

      帧动画——FrameAnimation 将一系列图片有序播放,形成动画的效果.其本质是一个Drawable,是一系列图片的集合,本身可以当做一个图片一样使用 在Drawable文件夹下,创建ani ...

  7. 分享9款用HTML5/CSS3制作的动物人物动画

    1.纯CSS3绘制可爱的蚱蜢 还有眨眼动画 今天我们要分享一个利用纯CSS3绘制的蚱蜢动画,非常可爱. 在线演示 源码下载 2.HTML5 Canvas头发飘逸动画 很酷的HTML5动画 HTML5 ...

  8. cocos2dx中创建动画的三种方法

    1.最最原始的方法,先创建动画帧,再创建动画打包(animation),再创建动画(animate) 第一步: 创建动画帧:CCSpriteFrame,依赖于原始的资源图片(xx.png,xx.jpg ...

  9. 使用javascript和css模拟帧动画的几种方法浅析

    我们平时在开发前端页面的时候,经常会播放一段帧序列.这段帧序列就像gif图片那样,反复循环播放.那大家可能会说,直接用gif图片就好了,干嘛还去模拟呢?那是因为要做得更加灵活,我们要做到以下几点: 1 ...

随机推荐

  1. CentOS 6.4 查看每个进程的网络流量

    所需工具nethogs 安装:yum install -y nethogs 使用:nethogs eth0

  2. 2分钟 windows下sublime text 3安装git插件:

    12:35 2015/11/182分钟 windows下sublime text 3安装git插件:推荐博客:http://blog.csdn.net/naola2001/article/detail ...

  3. codeforces589J 简单dfs,队列

    J. Cleaner Robot time limit per test 2 seconds memory limit per test 512 megabytes input standard in ...

  4. AE唯一值符号化的流程以及过程

    唯一值符号化的流程以及过程(转)   一.获取ServerStyle库中的符号       Style符号库在ArcGIS Engine开发中对应的是ServerStyle符号库,可以通过专门的转换程 ...

  5. 基于 Node.js 平台,快速、开放、极简的 web 开发框架。

    资料地址:http://www.expressjs.com.cn/ Express 基于 Node.js 平台,快速.开放.极简的 web 开发框架. $ npm install express -- ...

  6. find命令详解

    find命令详解   来源: ChinaUnix博客 日期: 2008.07.25 16:04 (共有条评论) 我要评论   [url=http://www.sudu.cn/web/host.php] ...

  7. tomcat 设置根目录访问

    from http://nj-apple-tree.iteye.com/blog/1635953 1,设置跟路径时,三种方式 在Tomcat默认安装后,tomcat的主目录是webapps/root目 ...

  8. [CareerCup] 17.6 Sort Array 排列数组

    17.6 Given an array of integers, write a method to find indices m and n such that if you sorted elem ...

  9. c#语句 随堂练习1

    1.请输入两个整数a,b,若a²+b²>100,则打印出a²+b²的结果,否则打印出a+b的结果. 2.有一组函数,y=x(x<1),y=2x-1(1<=x<10),y=3x- ...

  10. 在cenOS下安装apache出现-bash: /etc/init.d/httpd: 没有那个文件或目录

    我是在vmware上装的centos7,使用命令yum install httpd httpd-devel 安装完apache后,想要启动apache,执行了/etc/init.d/httpd sta ...