cocos2d-x创建精灵动画方式汇总
1、创建精灵框架缓存,并向其中添加相应的动画文件(plist),最后,通过动画集缓存生产动画
CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache();
cache->addSpriteFramesWithFile("animations/grossini.plist");
cache->addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png");
CCSpriteBatchNode *spritebatch = CCSpriteBatchNode::create("animations/grossini.png");//用于批量生产精灵
CCArray* animFrames = CCArray::createWithCapacity();//动态生成数组,类似于vector
for(int i = ; i < ; i++)
{
//sprintf的作用是字符串格式化,主要功能是把格式化的数据写入某个字符串中。sprintf(str, “ani_conch_%d.png”, 1)后str的值就变成了:ani_conch_1.png
sprintf(str, "grossini_blue_%02d.png",i);//两位数字,不够的话,用零补全
CCSpriteFrame *frame = cache->spriteFrameByName(str);
animFrames->addObject(frame);
}
animation = CCAnimation::createWithSpriteFrames(animFrames, 0.2f); //创建动画集,切换时间为0.2s
// Add an animation to the Cache
CCAnimationCache::sharedAnimationCache()->addAnimation(animation, "dance_blue"); // 把此动画集加入动画集缓存中,并命名为dance_blue
CCAnimationCache *animCache = CCAnimationCache::sharedAnimationCache(); //共享动画集缓存
CCAnimation *normal = animCache->animationByName("dance"); //获得动画集缓存
CCAnimate *animN = CCAnimate::create(normal); //创建动画
另外,CCString * str = CCString::createWithFormat("market_chipsLogo%d.png", idx);也可以实现替换数字的效果。
2、直接传入多个图片文件,生成动画
CCSprite *mainsprite=CCSprite::create("catBody1.png");
CCAnimation *animation=CCAnimation::create();
animation->addSpriteFrameWithFileName("catBody1.png");
animation->addSpriteFrameWithFileName("catBody2-4.png");
animation->addSpriteFrameWithFileName("catBody3.png");
animation->addSpriteFrameWithFileName("catBody2-4.png");
animation->setDelayPerUnit(0.1f);//设置动画的间隔时间
animation->setRestoreOriginalFrame(true);//是否返回第一帧
mainsprite->runAction(CCRepeatForever::create(CCAnimate::create(animation)));
3、直接传入一张大图,包含多个小图,生成动画
CCTexture2D *pTexture=CCTextureCache::sharedTextureCache()->addImage("hero.png");
CCSpriteFrame *frame0=CCSpriteFrame::createWithTexture(pTexture,CCRectMake(,,,));
CCSpriteFrame *frame1=CCSpriteFrame::createWithTexture(pTexture,CCRectMake(,,,));
CCSpriteFrame *frame2=CCSpriteFrame::createWithTexture(pTexture,CCRectMake(,,,));
CCSpriteFrame *frame3=CCSpriteFrame::createWithTexture(pTexture,CCRectMake(,,,));
CCArray *animFrames=CCArray::create();
CC_BREAK_IF(!animFrames);
animFrames->addObject(frame0);
animFrames->addObject(frame1);
animFrames->addObject(frame2);
animFrames->addObject(frame3);
CCAnimation *animation=CCAnimation::createWithSpriteFrames(animFrames,0.2f);
heroSprite0->runAction(CCRepeatForever::create(animate));
cocos2d-x创建精灵动画方式汇总的更多相关文章
- cocos3.0使用cocostudio动画帧结合地图对象键值创建精灵动画
内容例如以下: #include "cocos2d.h" #include "cocostudio/CocoStudio.h" //精灵猫和其它精灵的tag t ...
- cocos2d-x创建精灵动画
创建动画一般过程: 1.创建精灵框架缓存,并向其中添加相应的动画文件(plist),最后,通过动画集缓存生产动画 CCSpriteFrameCache *cache = CCSpriteFrameCa ...
- 精灵动画Animation对话框组成Idle动画的各精灵
精灵动画Animation对话框组成Idle动画的各精灵 1.3 精灵动画 场景中已经添加了精灵,现在是时候让让它动起来了.读者也许已经从精灵图集中,各精灵的命名中看出来了,这个精灵一共有两种动画状 ...
- 网页小实验——用canvas生成精灵动画图片
实验目标:借助canvas把一张国际象棋棋子图片转换为一组适用于WebGL渲染的精灵动画图片,不借助其他图片处理工具,不引用其他库只使用原生js实现. 初始图片如下: 一.图片分割 将初始图片分割为六 ...
- Cocos2d学习之路三(使用Zwoptex创建精灵表单和CCAnimate动画)
创建精灵表单: 创建动画先要把图片整合到一个图片上然后生成plist文件: 方法下载Zwoptex软件:http://www.zwopple.com/zwoptex/ 然后打开选择 create ne ...
- 创建帧动画1 - xml方式
废话不多说,先看东西 创建帧动画1 - xml方式 帧动画的创建方式主要以下2种: * 用xml创建动画: * 用代码创建动画: 本文内容主要关注 xml文件 创建帧动画的方式 xml文件 ...
- SpriteSheet精灵动画引擎
SpriteSheet精灵动画引擎 本文介绍Flash中SpriteSheet精灵序列图与其它渲染方式的性能对比.SpriteSheet的原理及注意实现,最后实现了一个精灵序列图的渲染引擎.本文的 ...
- css精灵动画
精灵动画的实现 CSS Sprites在国内很多人叫CSS精灵,其实这个技术不新鲜,原理就是:靠不断的切换图片让人感觉视觉上不断在变化,例如gif动画之类的效果 那么前端如何实现精灵效果? 传统的就是 ...
- Unity中的动画系统和Timeline(2) 按钮动画和2D精灵动画
按钮动画 1 创建按钮后,按钮的Button组件中,Transition我们平时用的时Tint,这次选择Animation 选择Auto Generate Animation,创建一个按钮动画 2 后 ...
随机推荐
- 编写高质量代码--改善python程序的建议(六)
原文发表在我的博客主页,转载请注明出处! 建议二十八:区别对待可变对象和不可变对象 python中一切皆对象,每一个对象都有一个唯一的标识符(id()).类型(type())以及值,对象根据其值能否修 ...
- [C#]Main(String[] args)参数输入问题
Main函数是程序的入口点,它是入口点,那它的参数,又是怎样来的呢?首先写个简单的测试程序看看args到底是什么? class Program { static void Main(string[] ...
- All thanks
How to make a salad?——Silun Wang 这是一次成功的团队合作,我为所有组员感到骄傲和自豪!感谢你们! 上个学期期末,和@老钱他们一起去五道口吃Pizza,谈到了大三上学期的 ...
- java.lang.IllegalStateException: getWriter() has already been called for this response问题解决
java.lang.IllegalStateException: getWriter() has already been called for this response问题解决 java.lang ...
- JDK的目录
要想深入了解Java必须对JDK的组成, 本文对JDK6里的目录做了基本的介绍,主要还是讲解 了下JDK里的各种可执行程序或工具的用途 Java(TM) 有两个平台 JRE 运行平台,包括Java虚拟 ...
- 泛——复习js高级第三版
1:本地存储的几种方法: (1)cookie: (2)localStorage //园子的自动保存就用了本地存储 (3)sessionStorage (4)globalStorage (5)index ...
- hdu1711 KMP
#include<stdio.h> #include<string.h> #define maxn 1000010 int next[maxn],s[maxn],p[maxn] ...
- MyEclipse 开发 Web项目发布到 Tomcat 下的Root 目录
通常情况下,Web项目是发布到Tomcat下的webapps文件目录下的 . 例如:Web应用项目名称为:stock,则部署到tomcat后,是部署在tomcat/webapps/stock中,网址为 ...
- 【bzoj4010】 HNOI2015—菜肴制作
http://www.lydsy.com/JudgeOnline/problem.php?id=4010 (题目链接) 题意 给出一张无向图要求出一个拓扑序列满足1的位置最靠前 ,在保证上面的条件下使 ...
- 【poj1716】 Integer Intervals
http://poj.org/problem?id=1716 (题目链接) 题意 给出n个区间,要求取出最少数量的不同的自然数,使每个区间中至少包含2个取出的数. Solution 差分约束. 运用前 ...