0

Does CCSpriteBatch node draw only sprites with visible property set to true?

Or does it consider also the screen size? In other words. If a sprite within the node is outside the screen, will the performance of the opengl draw call reflect that?

mm24
  • 9,280
  • 12
  • 75
  • 170
  • PS: after receiving the answer from LearnCocos2D I did some more research and found this question http://stackoverflow.com/questions/9502586/does-the-visible-property-affect-performance that confirms his answer. I add this just for additional reference material. – mm24 Sep 20 '12 at 19:31

1 Answers1

1

No and no.

CCSpriteBatchNode always draws all child sprites. I'm not sure exactly what makes sprites with visible = NO not to appear on screen, but technically it does draw all quads every time. It also doesn't take into account the screen area.

Sprites that are not batched behave differently. If a non-batched sprite is not visible, it's simply not drawn. Sprites outside the screen are drawn however. Cocos2D has no function ality to skip drawing of nodes outside the screen/window boundaries.

The following is hearsay, from what I've read over the past years, so take it with a grain of salt:

Too many batched sprites still affects performance negatively even if they are not visible or outside the screen. The GPU is responsible for cancelling draws of quads that are not visible due to being entirely outside the screen. It still needs to process those quads.

This is the main problem of cocos2d's tilemap implementation and why it is so slow with large tilemaps. Internally tilemaps also use the same sprite batching technique.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
  • so if I get it right, a sprite that is in a spritesheet but not added to a CCSpriteBatchNode is not considered by the GPU. But a sprite that is in a CCSpriteBatchNode and not visibile (e.g. not yet spawn and in a enemy cache) does affect the performance as the GPU needs to compute whether the corresponding quad is in the screen or not. Is this correct? – mm24 Sep 20 '12 at 19:30
  • regardless of the sprite being batched or not, if the sprite is offscreen, it's up to the GPU to determine that it doesn't have to draw the sprite – CodeSmile Sep 25 '12 at 10:14