3
votes

The benefit of using CCSpriteBatchNode is that each of its children is not separately drawn by OpenGL, thus if you have many images that are identical on the screen, it increases performance to use the batch node.

However, I am curious what happens if you load an entire texture atlas into CCSpriteBatchNode; does this mean that when you use a single sprite frame within that texture atlas, it is drawing (behind the scenes) all the sprite frames inside the texture?

In other words, is there any difference in performance between doing this:

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

 CCSpriteFrame *starFrame=[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"throwstar.png"];

stars=[CCSpriteBatchNode batchNodeWithTexture:starFrame.texture];

[self addChild:stars];

Or instead just using the entire texture atlas, rather than starFrame.texture for the batch node?

1

1 Answers

1
votes

The CCSpriteBatchNode draws its children. So only children added to it (which must be CCSprite objects) are drawn. And since the sprites use a CCSpriteFrame, each child only renders the part of the texture defined by the sprite frame.

The CCSpriteFrame object holds a reference to the texture it uses. This is the same texture as the CCSpriteBatchNode texture. In other words, the sprite frame's texture is always the texture of the texture atlas, not just a part of it. That's what the CGRect in CCSpriteFrame does, it instructs the sprite to only draw a specific region of the larger texture.