以下代码是在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 a RenderCommand to theRenderer, and Renderer is responsible for drawing the queued RenderCommand commands.
  • QuadCommands (used by Sprite and ParticleSystem objects) will be automatically batched.
  • CustomCommand objects allow the user to use custom OpenGL code, using a API similar to v2.2
  • GroupCommand objects allow to have "stacks" in the Renderer with different OpenGL values.
  • Auto-culling for Sprite objects (although, technically, Auto-culling is not performed in Renderer code, but in the Sprite 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 consecutive

If those conditions are met, the Renderer will create create a batch (one draw call) with all those QuadCommand 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):逐帧动画的更多相关文章

  1. Cocos2dx 3.1.1 学习笔记整理(1) 新建项目

    最近手痒了,不小心下载了cocos2dx 3.1.1,又搞了个VS2012,于是头脑发热的搞起 3.1.1了. 我是有多么的不专心啊. 已经把自己之前的学习内容从2.2.3迁移到了3.1.1,除了骨骼 ...

  2. Cocos2dx 3.1.1 学习笔记整理(2):创建场景与载入图片

    把之前用2.2.3的代码迁移到3.1.1真是个蛋疼的工作,话说3.1.1做的改动还真是大啊. 可以在HelloWorldScene.cpp中看到,之前的各种CCXXX都被废弃了. 例如,新建一个CCL ...

  3. Cocos2dx 3.1.1 学习笔记整理(4):事件监听与Action的初步使用

    项目忙,趁着刚才有点空,看了下触摸事件在新版本中怎么实现,遇到问题都是去:cocos2d-x-3.1.1\tests\cpp-tests\Classes下面找的,里面都是一些小例子. 首先新的CCNo ...

  4. python学习笔记整理——字典

    python学习笔记整理 数据结构--字典 无序的 {键:值} 对集合 用于查询的方法 len(d) Return the number of items in the dictionary d. 返 ...

  5. Deep Learning(深度学习)学习笔记整理系列之(五)

    Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...

  6. Deep Learning(深度学习)学习笔记整理系列之(八)

    Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...

  7. Deep Learning(深度学习)学习笔记整理系列之(七)

    Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...

  8. Deep Learning(深度学习)学习笔记整理系列之(六)

    Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...

  9. Deep Learning(深度学习)学习笔记整理系列之(四)

    Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...

随机推荐

  1. libc.so.6重做链接,删除导致的缺失问题(后期需要深入研究),未能成功升级

    中间件启动,提示/lib64/libc.so.6版本过低,升级glibc后,修改临时环境变量,结果导致sgment fault错误,根据报错 ll /lib64/ |grep libc -rwxr-x ...

  2. iOS View 模糊效果(毛玻璃)

    iOS View 模糊效果(毛玻璃)   相关资料 http://stackoverflow.com/questions/18404907/using-gpuimage-to-recreate-ios ...

  3. OpenGL------显示列表

    我们已经知道,使用OpenGL其实只要调用一系列的OpenGL函数就可以了.然而,这种方式在一些时候可能导致问题.比如某个画面中,使用了数千个多边形来表现一个比较真实的人物,OpenGL为了产生这数千 ...

  4. JAVA-面向对象2--继承

    1. 继承的好处: 1.提高代码复用性. 2.让类与类之间产生关系,为面向对象的第三大特征 多态 提供了前提 2.java中支持单继承,不直接支持多继承,但对c++中多继承进行了改良.java通过多实 ...

  5. gSoap工具wsdl2h及soapcpp2指令汇总

    gSoap开发包的下载地址http://sourceforge.net/projects/gsoap2,在bin目录下提供了两个工具: 1:wsdl2h:The gSOAP wsdl2h tool i ...

  6. Office2003/2010等集成SP的简单方法

    Office2003集成SP的简单方法 需要准备的工具:Office 2003 光盘镜像.SP3更新包.Office 2003 序列号.UltraISO,7-zip或winrar,虚拟光驱 步骤一:提 ...

  7. HBase性能优化方法总结(一):表的设计

    本文主要是从HBase应用程序设计与开发的角度,总结几种常用的性能优化方法.有关HBase系统配置级别的优化,可参考:淘宝Ken Wu同学的博客. 下面是本文总结的第一部分内容:表的设计相关的优化方法 ...

  8. Ubuntu下安装Reids

    安装 官网  http://redis.io/    下载安装包 redis-3.0.5.tar.gz 解压 tar -zxvf redis-3.0.5.tar.gz cd redis-3.0.5 安 ...

  9. java开发第一天

    今天是项目开始的时间,整体来说还是算顺利的.提前分好组,然后是听课时可以有人帮忙占座位的,感觉上是挺好的. 项目开发的难度看了看,由于有了第一次MFC开发的经验,所以这次听课感觉非常的有目标性,而且总 ...

  10. ab测试 uwsgi遇到的问题

    1 请求并发数目较大时,接收到的数目小于发送的数目 1.1 描述:uwsgi正常返回302跳转 ab -n 5000 -c 250 -g test.log "192.168.50.20:90 ...