johnbakers
johnbakers

Reputation: 24750

Role of CCSpriteBatchNode

The idea behind a CCSpriteBatchNode is to render a texture once for many sprites which should improve performance instead of treating each sprite as a different texture.

However, I'm confused how there is a benefit to using this as opposed to using only a single texture atlas. If you create a texture with this:

[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"gameTexture.plist"];

and then every single image you use for sprites is pulled using frame methods, then aren't all your images using the same single rendered texture, even though a batch node was never introduced?

Of course, you can use a batchnode in combination with a texture atlas, but how is this an actual gain in performance? If you do not use a batchnode, is it rendering the texture multiple times, even though it is cached?

Upvotes: 0

Views: 313

Answers (2)

FBryant87
FBryant87

Reputation: 4605

The performance improvement simple comes from the reduced number of OpenGL calls. If you don't use a SpriteBatchNode, your sprites will come from one texture yes but they will all make seperate OpenGL calls. The batch node object contains code to collect all of it's children and make just a single call, this is why your sprites must be a child of the same batch node to get the performance boost.

0 batch node + 100 sprites = 100 OpenGL calls.

1 batch node + 100 sprites (children of this batch node) = 1 OpenGL call.

If you're really interested have a look in CCSpriteBatchNode.m

Upvotes: 1

Ultrakorne
Ultrakorne

Reputation: 1303

using the same texture you are not changing texture at each call, but you still are rendering all the sprite in different glBegin and Ends, using the CCSpriteBatchNode will make sure that every sprite in it is rendered within the same call

Upvotes: 1

Related Questions