cocos2dx 3.x(实现帧动画(人物动画,跑马灯效果)的几种方法)
//创建一个跑酷的精灵
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(实现帧动画(人物动画,跑马灯效果)的几种方法)的更多相关文章
- WPF编程,通过【帧】动态更改控件属性的一种方法。
原文:WPF编程,通过[帧]动态更改控件属性的一种方法. 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net/qq_43307934/article/detail ...
- WPF编程,通过Path类型制作沿路径运动的动画一种方法。
原文:WPF编程,通过Path类型制作沿路径运动的动画一种方法. 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net/qq_43307934/article/de ...
- android ViewPager实现 跑马灯切换图片+多种切换动画
近期在弄个项目.要求有跑马灯效果的图片展示. 网上搜了一堆,都没有完美实现的算了还是自己写吧! 实现原理利用 ViewPager 控件,这个控件本身就支持滑动翻页非常好非常强大好多功能都能用上它.利用 ...
- 时光煮雨 Unity3D实现2D人物动画② Unity2D 动画系统&资源效率
系列目录 [Unity3D基础]让物体动起来①--基于UGUI的鼠标点击移动 [Unity3D基础]让物体动起来②--UGUI鼠标点击逐帧移动 时光煮雨 Unity3D让物体动起来③—UGUI DoT ...
- 时光煮雨 Unity3D实现2D人物动画① UGUI&Native2D序列帧动画
系列目录 [Unity3D基础]让物体动起来①--基于UGUI的鼠标点击移动 [Unity3D基础]让物体动起来②--UGUI鼠标点击逐帧移动 时光煮雨 Unity3D让物体动起来③—UGUI DoT ...
- android 帧动画,补间动画,属性动画的简单总结
帧动画——FrameAnimation 将一系列图片有序播放,形成动画的效果.其本质是一个Drawable,是一系列图片的集合,本身可以当做一个图片一样使用 在Drawable文件夹下,创建ani ...
- 分享9款用HTML5/CSS3制作的动物人物动画
1.纯CSS3绘制可爱的蚱蜢 还有眨眼动画 今天我们要分享一个利用纯CSS3绘制的蚱蜢动画,非常可爱. 在线演示 源码下载 2.HTML5 Canvas头发飘逸动画 很酷的HTML5动画 HTML5 ...
- cocos2dx中创建动画的三种方法
1.最最原始的方法,先创建动画帧,再创建动画打包(animation),再创建动画(animate) 第一步: 创建动画帧:CCSpriteFrame,依赖于原始的资源图片(xx.png,xx.jpg ...
- 使用javascript和css模拟帧动画的几种方法浅析
我们平时在开发前端页面的时候,经常会播放一段帧序列.这段帧序列就像gif图片那样,反复循环播放.那大家可能会说,直接用gif图片就好了,干嘛还去模拟呢?那是因为要做得更加灵活,我们要做到以下几点: 1 ...
随机推荐
- topcoder SRM 624 DIV2 BuildingHeightsEasy
从大到小遍历一遍,每次取M个元素,然后求得最小的floor即可 int minimum(int M, vector <int> heights) { sort(heights.begin( ...
- ACM: HDU 1874 畅通工程续-Dijkstra算法
HDU 1874 畅通工程续 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Desc ...
- PHP Pthread多线程 操作
<?php class vote extends Thread { public $res = ''; public $url = array(); public $name = ''; pub ...
- 获取系统开机的时间(Windows、Linux)
获取系统启动的时间.Windows系统和Linux系统 1.Windows系统 1)代码如下 #include <stdio.h> #include <time.h> #inc ...
- MyBatis增删改查
MyBatis的简介: MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation 迁移到了google code,并且改名 ...
- My租房网
阶段一:采用分页top关键字进行查询 实现6条~~10条出租信息 阶段2:查询指定客户发布的租房信息 查询客户张三的信息,使用连接查询实现. 阶段3:按区县制作房屋出租清单
- List相关知识点.......课堂加整理
package lis0924; //接口List(列表) import java.util.ArrayList; import java.util.Iterator; import java.uti ...
- Js变量定义——fn里 var与不var的区别
js运行时内置了一个Global对象. 这个Global对象跟运行环境有关.在浏览器运行环境中.Global就是window对象.在nodejs中.Global对象是global对象. 当你在浏览器环 ...
- jsTree 的简单用法--异步加载和刷新数据
首先这两个文件是必须要引用的,还有就是引用 jQuery 文件就不说了: <link href="/css/plugins/jsTree/style.min.css" rel ...
- 对Oracle10g rac srvctl命令使用理解
srvctl命令是RAC维护中最常用到的命令,也最为复杂,使用这个命令可以操作CRS上的Database,Instance,ASM,Service.Listener和Node Application资 ...