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 后 ...
随机推荐
- 传说中的WeixinJSBridge和微信rest接口
直接上图,金山的APP“微信导航”,从界面上看有粉丝数等关键数据,实现了直接关注功能,莫不是rest接口?这江湖是大佬们的江湖,小喽啰只有眼馋的份咯. 很早就听说过WeixinJSBridge,不过官 ...
- HDU 5115 Dire Wolf 区间dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5115 Dire Wolf Time Limit: 5000/5000 MS (Java/Others ...
- Date类型时间转换
/* 时间转换start */ public static void main(String args[]) { Date nowTime = new Date(); System.out.print ...
- 40.Android之新手指引界面学习
我们经常可以看到打开新App会有新手指引界面,类似蒙板效果今天来学习.原理其实很简单,设置一个透明Activity或者Dialog,然后修改其属性即可.由于实现比较简单,就贴一部分代码. 1.在And ...
- 细菌觅食算法-python实现
BFOIndividual.py import numpy as np import ObjFunction class BFOIndividual: ''' individual of bateri ...
- Penetration Testing、Security Testing、Automation Testing
相关学习资料 http://www.cnblogs.com/LittleHann/p/3823513.html http://www.cnblogs.com/LittleHann/p/3828927. ...
- TCP/IP详解 笔记九
广播和多播 多播和广播只能用于UDP包,TCP明确在两个进程间建立连接. 多播:帧只传送给属于多播组的多个接口 主机对帧的过滤过程: 通常网卡只接收那些目的地址为本物理接口地址或广播地址的帧:设置为混 ...
- MySql与Java的时间类型
MySql的时间类型有 Java中与之对应的时间类型date java.sql.DateDatet ...
- Java线程之间通信
用多线程的目的:更好的利用CPU的资源.因为所有的多线程代码都可以用单线程来实现. 多线程:指的是这个程序(一个进程)运行时产生了不止一个线程. 并行:多个CPU实例或者多台机器同时执行一段处理逻辑, ...
- TypeError: 'module' object is not callable cp fromhttp://blog.csdn.net/huang9012/article/details/17417133
程序代码 class Person: #constructor def __init__(self,name,sex): self.Name = name ...