问题
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