Cocos2d: Does CCSpriteBatch node draw only sprites

2019-03-04 02:14发布

问题:

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?

回答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.