//帧动画的创建
//方式一,通过多张图片来创建
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帧动画的更多相关文章

  1. cocos2dx 帧动画的两种创建方式

    看了好几天cocos2dx的帧动画,现在才有点眉目,为了高效期间我们一般会用到 精灵帧缓存(CCSpriteFrameCache) 和动画缓存(CCAnimationCache) .大体的操作步骤: ...

  2. cocos2dx 帧动画(iOS)

    植物大战僵尸的植物摇摆效果 //帧动画 Animation *animation = Animation::create(); Sprite *sprite = Sprite::create(&quo ...

  3. cocos2d-x 帧动画

    ani = cc.Animation:create(); ...... local animate = cc.Animate:create(ani); s:runAction(animate); 发现 ...

  4. Cocos2d-x开发实例介绍帧动画使用

    下面我们通过一个实例介绍一下帧动画的使用,这个实例如下图所示,点击Go按钮开始播放动画,这时候播放按钮标题变为Stop,点击Stop按钮可以停止播放动画. 下面我们再看看具体的程序代码,首先看一下看H ...

  5. COCOS2D-X之帧动画的一种实现Demo

    这个Demo主要是实现帧动画,建议游戏中少用帧动画.废话少说直接上代码. 一.我们直接在COCOS2D-X自带的HelloCpp的工程中添加代码即可.我们在初始化中添加如下代码并附上图片资源. CCS ...

  6. Cocos2d-x Lua中实例:帧动画使用

    下面我们通过一个实例介绍一下帧动画的使用,这个实例如下图所示,点击Go按钮开始播放动画,这时候播放按钮标题变为Stop,点击Stop按钮可以停止播放动画. 帧动画实例 下面我们再看看具体的程序代码,首 ...

  7. Cocos2d-x Lua中帧动画

    帧动画就是按一定时间间隔.一定的顺序.一帧一帧地显示帧图片.我们的美工要为精灵的运动绘制每一帧图片,因此帧动画会由很多帧组成,按照一定的顺序切换这些图片就可以了. 在Cocos2d-x Lua中播放帧 ...

  8. cocos2dx 3.x(实现帧动画(人物动画,跑马灯效果)的几种方法)

    //创建一个跑酷的精灵
  auto sprite = Sprite::create("1.png");
 //设置精灵的坐标
 sprite->setPosition(Ve ...

  9. cocos2d-x游戏开发(十六)帧动画

    欢迎转载:http://blog.csdn.net/dawn_moon/article/details/11775745 本来想写一下帧动画的,搜了一下网上好像有一大把,就懒得写了,直接贴代码. // ...

随机推荐

  1. hdu4121 poj4001 Xiangqi(模拟)

    模拟题考验coding能力,一定要思路清晰,按照模块化思想,有哪些情况,需要哪些功能都要事先分析好了.高手的模拟题代码往往结构很清晰,功能模块写成函数,没有过多重复代码,让人一看便明. 方法选择的好坏 ...

  2. 【phpcms-v9】前台content模块中pc标签的调用说明

    内容模块PC标签调用说明 模块名:content 模块提供的可用操作 操作名 说明 lists 内容数据列表 relation 内容相关文章 hits 内容数据点击排行榜 category 内容栏目列 ...

  3. 修改altibase MDB中的复制表的表结构

    前提条件:有MDB两个数据库,且知道普通用户和sys用户的密码等基本信息.操作:1:用sys用户登录isqlisql -s 127.0.0.1 -u sys -p manager -port 2030 ...

  4. ACC 001 C - Shorten Diameter 图论

    题目: Problem Statement Given an undirected tree, let the distance between vertices \(u\) and \(v\) be ...

  5. 使用sort&awk实现文件内容块排序

    源文件为: [root@luo5 wangxx]# cat -v luo.txt J LuoSoutth jfsaNanjing,china Y ZhangVictory UniversityNejf ...

  6. ASP.NET MVC 缓存Outputcache (局部动态)

    首先说一下需求: 比如我需要对网站首页做缓存,于是在首页对于的Action上贴上了Outputcache,接着问题就来了,首页上的有部分数据是不能做缓存的,比如个人信息,不然,每个人登陆都是看到第一个 ...

  7. IntellJ IDEA快捷键汇总

    今天开始使用IDEA,各种不习惯,一会Eclipse一会IDEA来回切换,需要一个熟悉的过程,记录一下常用的快捷键. IDEA常用快捷键 Alt+回车 导入包,自动修正Ctrl+N  查找类Ctrl+ ...

  8. CAS环境搭建-证书方式(https连接)

    一.教程前言 1 教程目的:从头到尾细细道来单点登录服务器及客户端应用的每个步骤 2 单点登录(SSO):请看<CAS简介> 3 本教程使用的SSO服务器是Yelu大学研发的CAS(Cen ...

  9. VC 6.0下载 VC 6.0英文版下载 Visual C++ 6.0 英文企业版 集成SP6完美版(最新更新地址,百度网盘)

    下载地址1:Visual.C++.6.EN 下载地址2:Visual.C++.6.EN 更新下载地址可用(百度网盘)Visual.C++.6.EN 转载请注明出处,有技术问题,欢迎互相交流,或者留言.

  10. MyBatis定制SQL集中特殊的处理方式

    举例说明: 1.查询 姓为林的数据  LIKE 3种 Select * from sys_user where user_name like '林%' 关于结果集合多个参数传递数据 特殊字符的处理