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 aRenderCommandto theRenderer, andRendereris responsible for drawing the queuedRenderCommandcommands.QuadCommands(used bySpriteandParticleSystemobjects) will be automatically batched.CustomCommandobjects allow the user to use custom OpenGL code, using a API similar to v2.2GroupCommandobjects allow to have "stacks" in the Renderer with different OpenGL values.- Auto-culling for
Spriteobjects (although, technically, Auto-culling is not performed inRenderercode, but in theSpritecode)- Global Z ordering (local Z ordering is still supported)
Renderer features
Auto-batching
Auto-batching means that the
Rendererwill 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
QuadCommandcommands (used by Sprite and ParticleSystem objects)- The
QuadCommandsmust share the same Material ID: same Texture ID, same GLProgram and same blending function- The
QuadCommandsmust consecutiveIf those conditions are met, the
Rendererwill create create a batch (one draw call) with all thoseQuadCommandobjects.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 ...
随机推荐
- linux 命令汇总
一 Grep 命令 各种参数: -i:ignore-case忽略大小写 -c :打印匹配的行数 -l :从多个文件中查找包含匹配项 -v :查找不包含匹配项的行 -n :打印包含匹配项的行和行标 -w ...
- Android Matrix类以及ColorMatri
引自:http://www.chinabaike.com/t/37396/2014/0624/2556217.html Android Matrix类以及ColorMatrix类详解 最近在系统学习了 ...
- 取消svn版本控制
删除项目中的版本控制,即删除项目文件夹下的所有.svn文件夹(在做项目的时候,有时候想把项目拷回去看看,但是文件太大了,而且压缩起来很慢.这主要是因为在项目中有大量的.svn文件夹.所以才想把.svn ...
- JS限制 获取动太ID,播放视频
JS限制textarea字数 function textdown(e) {textevent = e ; ) { return; } ) { alert("大侠,我手机屏幕小,先输入这么多字 ...
- ssh登录nat模式的VMware虚拟机
有时候本地PC是固定IP上网方式且无多余IP,而我们又希望使用putty登陆VMware中的虚拟机且虚拟机可以上外网,那么这时候就可以使用端口映射. 1.本地环境简述 本地PC IP:192.168. ...
- elasticsearch 索引优化
ES索引优化篇主要从两个方面解决问题,一是索引数据过程:二是检索过程. 索引数据过程我在上面几篇文章中有提到怎么创建索引和导入数据,但是大家可能会遇到索引数据比较慢的过程.其实明白索引的原理就可以有 ...
- 学习笔记——组合模式Composite
组合模式,典型的层次结构. 与装饰器类图相似. 区别在于:装饰器模式是为了在接口中增加方法,而组合模式在于层次元素的叠加. ConcreteComponent就是中间结点,可以包含更多的Concret ...
- CodeForces 412D Giving Awards
根据给出的条件建边,然后进行dfs 对于某个点x,当x的后继都遍历完毕后,再输出x节点. 这样能保证所有约束条件. #include<cstdio> #include<cstring ...
- HDU 2672 god is a girl
先找规律,发现是斐波那契数列...然后..水题.. #include<cstdio> #include<cstring> #include<cmath> #incl ...
- jq的合成事件
jq中有两个合成事件 hover()和toggle() 1.hover() hover方法用于模拟光标悬停事件.当光标移动到元素上时,会触发指定的第一个函数(enter),当光标移出这个元素时,会触发 ...