Cocos2dx 3.1.1 学习笔记整理(3):逐帧动画
以下代码是在cocos中使用,plist+png 还有SpriteBatchNode播放动画的代码,备份一下,以防git被墙:
bool GameMain::init()
{
if( !Layer::init())
return false;
Size visibleSize = CCDirector::sharedDirector()->getVisibleSize();
bg = Sprite::create("battle.png");
bg->setPosition(visibleSize.width/, visibleSize.height/);
addChild(bg); auto batchNode = SpriteBatchNode::create("huangfeihu.png",);
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("huangfeihu.plist"); Vector<SpriteFrame*> hfhFrames();
char str[] = {};
for( int i = ; i < ; i++ )
{
sprintf(str, "huangfeihu%d.png",i);
auto frame = SpriteFrameCache::getInstance()->spriteFrameByName(str);
if( frame != NULL )
hfhFrames.pushBack(frame);
} for( int j = ; j < ; j++ )
{
auto hfh = Sprite::createWithSpriteFrameName("huangfeihu0.png");
auto anim = Animation::createWithSpriteFrames( hfhFrames,0.05f );
hfh->runAction(RepeatForever::create( Animate::create(anim)));
hfh->setPosition(visibleSize.width*rand()/RAND_MAX, visibleSize.height*rand()/RAND_MAX);
batchNode->addChild(hfh); }
this->addChild(batchNode);
return true;
}
结果如下:
2014-6-26补:
刚才在cocos2dx官网看了下cocos2dx-3.x的版本更新内容。发现以下:
New Renderer
Features of the new renderer:
- It has been decoupled from the Scene Graph. The
draw()
method, instead of "drawing" it sends aRenderCommand
to theRenderer
, andRenderer
is responsible for drawing the queuedRenderCommand
commands.QuadCommands
(used bySprite
andParticleSystem
objects) will be automatically batched.CustomCommand
objects allow the user to use custom OpenGL code, using a API similar to v2.2GroupCommand
objects allow to have "stacks" in the Renderer with different OpenGL values.- Auto-culling for
Sprite
objects (although, technically, Auto-culling is not performed inRenderer
code, but in theSprite
code)- Global Z ordering (local Z ordering is still supported)
Renderer features
Auto-batching
Auto-batching means that the
Renderer
will package "multiple draw calls" in just one "big draw call" (AKA batch). In order to group "draw calls" certain conditions are needed:
- It only works with
QuadCommand
commands (used by Sprite and ParticleSystem objects)- The
QuadCommands
must share the same Material ID: same Texture ID, same GLProgram and same blending function- The
QuadCommands
must consecutiveIf those conditions are met, the
Renderer
will create create a batch (one draw call) with all thoseQuadCommand
objects.In case you are unfamiliar with the OpenGL best practices, batching is very important to have decent speed in your games. The less batches (draw calls) the more performance your game is going to be.
Sprite vs. SpriteBatchNode
To summarize:
- Keep putting all your sprites in a big spritesheet
- Use the same Blending Function (just use the default one)
- Use the same Shader (just use the default one)
- And don't parent your sprites to a
SpriteBatchNode
大意是在cocos2dx 3.x中尽量避免使用SpriteNodeBatch,
尽量将Sprite的素材放到一个SpriteSheet中,
因为Sprite是使用QuadBatchCommand去渲染的,
而QuadBatchCommand默认是batch(批处理的)的。
原文参考:
https://github.com/cocos2d/cocos2d-x/blob/cocos2d-x-3.0/docs/RELEASE_NOTES.md
Cocos2dx 3.1.1 学习笔记整理(3):逐帧动画的更多相关文章
- Cocos2dx 3.1.1 学习笔记整理(1) 新建项目
最近手痒了,不小心下载了cocos2dx 3.1.1,又搞了个VS2012,于是头脑发热的搞起 3.1.1了. 我是有多么的不专心啊. 已经把自己之前的学习内容从2.2.3迁移到了3.1.1,除了骨骼 ...
- Cocos2dx 3.1.1 学习笔记整理(2):创建场景与载入图片
把之前用2.2.3的代码迁移到3.1.1真是个蛋疼的工作,话说3.1.1做的改动还真是大啊. 可以在HelloWorldScene.cpp中看到,之前的各种CCXXX都被废弃了. 例如,新建一个CCL ...
- Cocos2dx 3.1.1 学习笔记整理(4):事件监听与Action的初步使用
项目忙,趁着刚才有点空,看了下触摸事件在新版本中怎么实现,遇到问题都是去:cocos2d-x-3.1.1\tests\cpp-tests\Classes下面找的,里面都是一些小例子. 首先新的CCNo ...
- python学习笔记整理——字典
python学习笔记整理 数据结构--字典 无序的 {键:值} 对集合 用于查询的方法 len(d) Return the number of items in the dictionary d. 返 ...
- Deep Learning(深度学习)学习笔记整理系列之(五)
Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...
- Deep Learning(深度学习)学习笔记整理系列之(八)
Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...
- Deep Learning(深度学习)学习笔记整理系列之(七)
Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...
- Deep Learning(深度学习)学习笔记整理系列之(六)
Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...
- Deep Learning(深度学习)学习笔记整理系列之(四)
Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...
随机推荐
- web-service客户端与服务器端的连接
1 首先讲解下xfire XFire是新一代的Java Web服务引擎,XFire使得在JavaEE应用中发布Web服务变得轻而易举.和其他Web服务引擎相比,XFire的配置非常简单,可以非常容易地 ...
- 标签—box-shadow
box-shadow:2px 3px 4px #CCC; 一个带外阴影的元素,阴影位置x轴偏移2px,y轴偏移3px,模糊范围4px,阴影颜色#CCC box-shadow:inset 0 -4px ...
- JNI调用问题(部分机型崩溃)
1.今日测试发现在部分手机上游戏会崩溃,通过logcat日志发现是jni调用问题(我猜测) 错误日志中有如下语句: trying to work around app JNI bugs, but di ...
- HDU 1010 Tempter of the Bone DFS(奇偶剪枝优化)
需要剪枝否则会超时,然后就是基本的深搜了 #include<cstdio> #include<stdio.h> #include<cstdlib> #include ...
- keyboardWillChangeFrameNotification 引发的思考 是的 思考了很久终于出结果
func keyboardWillChangeFrameNotification(note: NSNotification) { // TODO 添加键盘弹出的事件 let userinfo = no ...
- 第一章C语言简介及输出函数 上机部分
第一章C语言简介及输出函数 上机1 #include "stdio.h" void main() { printf("南方学院,你好!\n"); printf( ...
- SSL交互过程
SSL交互过程 HTTPS将HTTP和SSL结合,即加了SSL隧道封装的HTTP,通过SSL对客户端身份和服务器进行验证,对传输的数据进行加密.不同情况下SSL的协商过程存在差异,本节以只验证服务器为 ...
- Lucene + Hadoop 分布式搜索运行框架 Nut 1.0a9转自http://www.linuxidc.com/Linux/2012-02/53113.htm
1.概述 不管程序性能有多高,机器处理能力有多强,都会有其极限.能够快速方便的横向与纵向扩展是Nut设计最重要的原则,以此原则形成以分布式并行计算为核心的架构设计.以分布式并行计算为核心的架构设计是N ...
- Oracle Sql优化之范围处理
1.表中字段自关联与分析函数的性能比较,自关联需要扫描表两次,分析函数扫描一次即可 ----自关联 select v1.proj_id,v1.proj_start,v1.proj_end from v ...
- 逆序一个8bit的2进制数