cocos2dx 3.x避免空customCommand
1,导致性能悲剧的写法:
class A:public CCNode{
public:
A(){
m_sprite=NULL;
m_isDrawDebug=false;
}
virtual~A(){}
bool init(){
this->CCNode::init();
//create m_sprite
m_sprite=CCSprite::create();
m_sprite->initWithFile("a.png");
addChild(m_sprite);
....
return true;
}
void draw(Renderer* renderer, const Mat4& transform, uint32_t transformFlags){
_customCommand_drawDebug(_globalZOrder);
_customCommand_drawDebug = CC_CALLBACK_0(A::onDrawDebug,this,transform, transformFlags);
renderer->addCommand(&_customCommand_drawDebug);
}
void onDrawDebug(const Mat4 &transform, uint32_t transformFlags){
if(m_isDrawDebug){
//draw debug
...
}
}
public:
CCSprite*m_sprite;
bool m_isDrawDebug;
CustomCommand _customCommand_drawDebug;
};
上面写法,无论m_isDrawDebug是true还是false,如果场景中加1000个对象a,drawCall数量为1000。
2,不损失性能的写法:
class A:public CCNode{
public:
A(){
m_sprite=NULL;
m_isDrawDebug=false;
}
virtual~A(){}
bool init(){
this->CCNode::init();
//create m_sprite
m_sprite=CCSprite::create();
m_sprite->initWithFile("a.png");
addChild(m_sprite);
....
return true;
}
void draw(Renderer* renderer, const Mat4& transform, uint32_t transformFlags){
if(m_isDrawDebug){
_customCommand_drawDebug(_globalZOrder);
_customCommand_drawDebug = CC_CALLBACK_0(A::onDrawDebug,this,transform, transformFlags);
renderer->addCommand(&_customCommand_drawDebug);
}
}
void onDrawDebug(const Mat4 &transform, uint32_t transformFlags){
//draw debug
...
}
public:
CCSprite*m_sprite;
bool m_isDrawDebug;
CustomCommand _customCommand_drawDebug;
};
上面写法当m_isDrawDebug为false时,如果场景中加1000个对象a,则drawCall数量为1。
cocos2dx 3.x避免空customCommand的更多相关文章
- cocos2dx 3.x 避免空sprite
由于cocos2dx 3.x中autobatch的,如果场景中含有空sprite(并且还不处于visible==false状态)的话,则会打断流水线(因为空sprite的贴图与其它元素的贴图必定不在同 ...
- Cocos2dx源码赏析(2)之渲染
Cocos2dx源码赏析(2)之渲染 这篇,继续从源码的角度来跟踪下Cocos2dx引擎的渲染过程,以此来梳理下Cocos2dx引擎是如何将精灵等元素显示在屏幕上的. 从上一篇对Cocos2dx启动流 ...
- 基于Cocos2d-x学习OpenGL ES 2.0系列——OpenGL ES渲染之LayerColor(8)
在前面文章中讲述了Cocos2d-x引擎OpenGL渲染准备Shader方面,本文主要讲解使用LayerColor来讲述OpenGL的渲染过程. 1.LayerColor对象创建 添加LayerCol ...
- cocos2D-X从的源代码的分析cocos2D-X学习OpenGL(1)----cocos2D-X渲染架构
个人原创.欢迎转载,转载请注明原文地址http://blog.csdn.net/bill_man 从本篇文章開始,将分析cocos2D-X 3.0源码,第一部分是从cocos2D-X学习OpenGL ...
- 我所理解的Cocos2d-x
我所理解的Cocos2d-x(完全基于Cocos2d-x3.0,深度剖析计算机图形学,OpenGL ES及游戏引擎架构,全面提升游戏开发相关知识) 秦春林 著 ISBN 978-7-121-246 ...
- Cocos2d-x 3.2 学习笔记(四)学习打包Android平台APK!
从cocos2dx 3.2项目打包成apk安卓应用文件,搭建安卓环境的步骤有点繁琐,但搭建一次之后,以后就会非常快捷! (涉及到3.1.1版本的,请自动对应3.2版本,3.x版本的环境搭建都是一样的) ...
- Cocos2d-x 3.2学习笔记(三)学习绘图API
关于cocos2d-x 3.2 版本的绘图方法有两种 1.使用DrawNode类绘制自定义图形. 2.继承Layer类重写draw()方法. 以上两种方法都可以绘制自定义图形,根据自己的需要选择合适的 ...
- [cocos2d-x]深入--几个代表性的类
摘要: 此文对cocos2d-x引擎中最具代表性,最能体现框架结构的几个类做了简单的介绍, 包括Director,Application, Renderer, EventDispatcher, Sch ...
- 学习cocos 空程序
今天开始学习cocos代码,首先研究源码中的空程序. 在这个程序中,在main函数中,创建了一个Application: int APIENTRY _tWinMain(HINSTANCE hInsta ...
随机推荐
- windows server2012部署Cognos问题小结
一:数据库配置问题 1:.net Framework3.5问题 window Server2012 安装数据库的时候可能会报缺少.net Framework3.5,需要去服务管理器添加.net F ...
- SharePoint 2013网站突然不能登录了。
SharePoint 2013网站突然不能登录了,访问的时候,总是报错: The list has not shared with you. 原因: 原来我不知道什么时候把web applicat ...
- ElasticSearch关闭重启命令
很多人学习elasticSearch都是自学,想百度一下如何重启es也是没有答案,我硬着头皮,算是琢磨出来了,借此写博,希望能帮助您. 1.如何关闭ES,elasticsearch关闭办法 1.使用h ...
- tiny210(s5pv210)移植u-boot(基于 2014.4 版本号)——移植u-boot.bin(打印串口控制台)
在之前我们移植的代码中,都没看到明显的效果,这节我们实现控制台的信息打印. 在上节.我们看到调用 relocate_code 重定位.在 u-boot 的帮助文档 doc/README.arm-rel ...
- glibc的几个有用的处理二进制位的内置函数(转)
— Built-in Function: int __builtin_ffs (unsigned int x) Returns one plus the index of the least sign ...
- eclipse no java machine vitual was found
eclipse no java machine vitual was found CreateTime--2018年4月27日10:41:20 Author:Marydon 1.错误提示 2.问题 ...
- [Done]BTrace使用小记
项目上线,发现集群机器每隔1小时会准时进行fullgc,JMC中显示了System.gc()触发了fullgc: 代码搜了一下自然是搜不到显示调用这个代码的(谁会这么干!拍死!!!)依赖jar包中到是 ...
- 创建简单的Telnet实例
step1.先加入库SuperSocket.Common.dll, SuperSocket.SocketBase.dll, SuperSocket.SocketEngine.dll,log4net.d ...
- js 面向对象式编程
1.声明一个函数,在函数内进行初始化操作,,函数不能有返回值2.把需要的参数传递进去,参数最好以对象形式传入,如果有默认的设置默认参数3.把传入的参数都保存到对象的属性上面4.把初始化操作中需要用到的 ...
- 【LeetCode】124. Binary Tree Maximum Path Sum
Binary Tree Maximum Path Sum Given a binary tree, find the maximum path sum. The path may start and ...