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 ...
随机推荐
- Codeforces Round #249 (Div. 2) A - Queue on Bus Stop
水题 #include <iostream> #include <vector> #include <algorithm> using namespace std; ...
- Linux远程传输命令之scp使用方法
首先用pwd命令确定文件全路径 1.获取远程服务器上的文件 cykdeMacBook-Pro:~ cyk$ scp cyk@10.211.55.5:/home/cyk/Desktop/hi.t ...
- nfs的使用
1.安装命令:sudo apt-get install nfs-kernel-server ; sudo apt-get install nfs-common; 2.执行命令:mkdir /(目录 ...
- 基于S5PC100裸机程序之SPI(上)
作者:杨老师,华清远见嵌入式学院讲师. SPI作为应用最为广泛的通信总线协议之一,开发人员应当掌握,本章将介绍SPI总线协议的基本理论,以及S5PC100的SPI总线控制器的操作方法. 1. SPI总 ...
- Jquery Ajax方法传值到action
假设cshtml文件中是这样的: <script type="text/javascript"> $(document).ready(function(){ $(&qu ...
- jquery中prop()方法和attr()方法的区别浅析
官方例举的例子感觉和attr()差不多,也不知道有什么区别,既然有了prop()这个新方法,不可能没用吧,那什么时候该用attr(),什么时候该用prop()呢 jquery1.6中新加了一个方法pr ...
- Windows8.1自定义快捷方式添加到开始屏幕
Windows8.1自定义快捷方式添加到开始屏幕 将快捷方式复制到如下路径,在开始屏幕的所有中找到对应快捷方式,右键选择添加到开始屏幕即可. C:\Users\%USERNAME%\AppData\R ...
- .net 实现Office文件预览,word文件在线预览、excel文件在线预览、ppt文件在线预览
转自源地址:http://www.cnblogs.com/GodIsBoy/p/4009252.html,有部分改动 使用Microsoft的Office组件将文件转换为PDF格式文件,然后再使用pd ...
- FTP目录或文件名有中文时导致,下载失败的问题
在FTPClient ftpClient = new FTPClient()代码后, ftpClient.connect(url,port)代码前, 调用ftpClient.setAutodetect ...
- jquery ui dialog去掉右上角的叉号
var dialog = $("#id").dialog({ resizable:false, height:, width:, zIndex:, modal:true, open ...