//创建一个跑酷的精灵

 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. RequireJS 循环依赖报 模块undefined 处理方案

    RequireJS 循环依赖 开始学习使用RequireJS之后做了几个小例子,之后想着把手头的项目也用RequireJS写一遍试试.感觉胜利就在前方了,忽然发现始终卡在一个问题上: 很常见的一个问题 ...

  2. 洛谷 P1462 通往奥格瑞玛的道路 Label: 最小化最大值 && spfa (存多条边示例)

    题目背景 在艾泽拉斯大陆上有一位名叫歪嘴哦的神奇术士,他是部落的中坚力量 有一天他醒来后发现自己居然到了联盟的主城暴风城 在被众多联盟的士兵攻击后,他决定逃回自己的家乡奥格瑞玛 题目描述 在艾泽拉斯, ...

  3. 3801. String LD

    Description Stringld (left delete) is a function that gets a string and deletes its leftmost charact ...

  4. 【HDU】4418 Time travel

    http://acm.hdu.edu.cn/showproblem.php?pid=4418 题意:一个0-n-1的坐标轴,给出起点X.终点Y,和初始方向D(0表示从左向右.1表示从右向左,-1表示起 ...

  5. 练习一:SQLite基本操作

    一.基础知识: 运用场景: 1>应用运行需要保存一系列有一定关系有一定结构的数据(文本也可以但是存储效率低) 2>文件类型:.db(一个数据库就是一个.db文件) 3>路径:/dat ...

  6. 32位的Win7系统下安装64位的Sql Sever?

    来自:http://zhidao.baidu.com/link?url=nQBoaLgoOyYCUdI7V4WZCMlTW3tKscdkOnLTIvlYtPpwoVhQkSahq44HeofBfzFT ...

  7. iframe自适应高度js

    <iframe src="http://www.fufuok.com/" id="iframepage" name="iframepage&qu ...

  8. daterangepicker 日期范围插件自定义 可选 年份

    minDate:'01/01/2012',maxDate:'01/01/2015' $("#txtPODate").daterangepicker({ singleDatePick ...

  9. eclipse中如何修改dynamic web module version

    java项目中,若切换服务器,经常会涉及到动态web模块版本的问题.      比如:新建了web项目,开始使用tomcat服务器,但是后来使用jboss服务器,就会出现:Project facet ...

  10. Oracle数据库更新时间的SQL语句

    ---Oracle数据库更新时间字段数据时的sql语句---格式化时间插入update t_user u set u.name='pipi',u.modifytime=to_date('2015-10 ...