Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the .visible property affect performance?

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?

like image 808
Voldemort Avatar asked Jan 26 '26 11:01

Voldemort


2 Answers

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.

like image 143
Ken Toh Avatar answered Jan 29 '26 10:01

Ken Toh


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.

like image 24
Sebastián Castro Avatar answered Jan 29 '26 09:01

Sebastián Castro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!