cocos2dx帧动画
//帧动画的创建
//方式一,通过多张图片来创建
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;
cocos2dx帧动画的更多相关文章
- cocos2dx 帧动画的两种创建方式
看了好几天cocos2dx的帧动画,现在才有点眉目,为了高效期间我们一般会用到 精灵帧缓存(CCSpriteFrameCache) 和动画缓存(CCAnimationCache) .大体的操作步骤: ...
- cocos2dx 帧动画(iOS)
植物大战僵尸的植物摇摆效果 //帧动画 Animation *animation = Animation::create(); Sprite *sprite = Sprite::create(&quo ...
- cocos2d-x 帧动画
ani = cc.Animation:create(); ...... local animate = cc.Animate:create(ani); s:runAction(animate); 发现 ...
- Cocos2d-x开发实例介绍帧动画使用
下面我们通过一个实例介绍一下帧动画的使用,这个实例如下图所示,点击Go按钮开始播放动画,这时候播放按钮标题变为Stop,点击Stop按钮可以停止播放动画. 下面我们再看看具体的程序代码,首先看一下看H ...
- COCOS2D-X之帧动画的一种实现Demo
这个Demo主要是实现帧动画,建议游戏中少用帧动画.废话少说直接上代码. 一.我们直接在COCOS2D-X自带的HelloCpp的工程中添加代码即可.我们在初始化中添加如下代码并附上图片资源. CCS ...
- Cocos2d-x Lua中实例:帧动画使用
下面我们通过一个实例介绍一下帧动画的使用,这个实例如下图所示,点击Go按钮开始播放动画,这时候播放按钮标题变为Stop,点击Stop按钮可以停止播放动画. 帧动画实例 下面我们再看看具体的程序代码,首 ...
- Cocos2d-x Lua中帧动画
帧动画就是按一定时间间隔.一定的顺序.一帧一帧地显示帧图片.我们的美工要为精灵的运动绘制每一帧图片,因此帧动画会由很多帧组成,按照一定的顺序切换这些图片就可以了. 在Cocos2d-x Lua中播放帧 ...
- cocos2dx 3.x(实现帧动画(人物动画,跑马灯效果)的几种方法)
//创建一个跑酷的精灵 auto sprite = Sprite::create("1.png"); //设置精灵的坐标 sprite->setPosition(Ve ...
- cocos2d-x游戏开发(十六)帧动画
欢迎转载:http://blog.csdn.net/dawn_moon/article/details/11775745 本来想写一下帧动画的,搜了一下网上好像有一大把,就懒得写了,直接贴代码. // ...
随机推荐
- ubuntu16.04下安装配置深度学习环境(Ubuntu 16.04/16.10+ cuda7.5/8+cudnn4/5+caffe)
主要参照以下两篇博文:http://blog.csdn.net/g0m3e/article/details/51420565 http://blog.csdn.net/xuzhongxiong/a ...
- Project://STARK
数据添加&编辑 删除&分页 搜索框功能 action批量操作 filter多条件过滤 pop_up弹窗
- POJ - 2891 Strange Way to Express Integers (扩展中国剩余定理)
题目链接 扩展CRT模板题,原理及证明见传送门(引用) #include<cstdio> #include<algorithm> using namespace std; ty ...
- CodeForces - 682E: Alyona and Triangles(旋转卡壳求最大三角形)
You are given n points with integer coordinates on the plane. Points are given in a way such that th ...
- lower_bound()函数与quicksort()函数的简单掌握
lower_bound 这个序列中可能会有很多重复的元素,也可能所有的元素都相同,为了充分考虑这种边界条件,STL中的lower_bound算法总体上是才用了二分查找的方法,但是由于是查找序列中的第一 ...
- [Luogu3727]曼哈顿计划E
luogu 题意(简化版) 给你一棵树,每个点上有一个\(SG\)值,问你是否存在一条路径使得\(SG\)异或和为\(0\). sol 可以当做每个点的稳定值就是这个点上的石子数量. 很显然我们只需要 ...
- WINRAR4.2破解方式或注册码
急求WINRAR4.2破解方式或注册码,谢谢大侠们!~ 亲,我是复制别个的但是可以用64位32位都可以用 自己动手破解 那感觉才棒! 来吧 将以下数据复制到记事本中 然后另存名为“rarreg.key ...
- mysql之 Innobackupex(全备+增量)备份恢复
MySQL的热备(物理备份)可以采取全备加增量备份的方式来减轻数据库I/O压力及系统资源的占用.增量备份主要是以全备或增量备份为基础,备份那些变更过的页面.其备份的原理是基于一个不断增长的LSN序列, ...
- js性能优化文章集锦
总结的js性能优化方面的小知识http://www.it165.net/pro/html/201503/35336.html 如何优化你的JS代码http://www.php100.com/html/ ...
- (转)C#程序开发中经常遇到的10条实用的代码
原文地址:http://www.cnblogs.com/JamesLi2015/p/3147986.html 1 读取操作系统和CLR的版本 OperatingSystem os = System.E ...