Does the .visible property affect performance?

喜夏-厌秋 提交于 2019-12-18 05:12:44

问题


I can turn the .visible value for CCNodes, but I wonder, can an insivisible node consume less memory/processing than a visible one? Can I set the .visible property to NO when my objects are outside the screen to optimize? Or does cocos2d already do that stuff for me?


回答1:


Invisible nodes are typically skipped when it comes to being rendered. On the other hand, nodes with visible set to YES will invoke OpenGL draw calls, regardless of whether they are on or off the screen (See Riq's comment here). ie. cocos2d does not seem to perform any kind of culling for offscreen elements.

If this is indeed the case, I would simply just set visible = NO (no harm and definitely not hard!) if they are completely off the screen to avoid invoking any additional draw calls. Also note that these offscreen node objects are still physically present and still take up the same memory, even if they have visible set to NO. Furthermore, if these nodes are already running some animations/actions, they will continue updating outside the screen, unless you unschedule them.




回答2:


Check this posts from the official cocos2d forum

is rendering invisible sprites in spritebatchnode cheap?

Performance Difference between visible = no and removeChild

Bad perfomance - many sprites with the same texture

Also, you can test it by yourself but i think that those post will help.

IMO setting visible=NO is enough, but depends on the sprite count.



来源:https://stackoverflow.com/questions/9502586/does-the-visible-property-affect-performance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!