Why load sprite as CCSpriteBatchNode gain efficiency?

As mentioned in this tutorial for animation using CCSpriteBatchNode :
http://www.raywenderlich.com/1271/how-to-use-animations-and-sprite-sheets-in-cocos2d

I’m curious to know why using CCSpriteBatchNode can be more efficient?

If I allocate a array of CCSprite * instead of using CCSpriteBatchNode, the memory we used should be same, right?

I can accept the idea that using CCTextureCache can be more efficient if you have multiple object using the same texture.

However, in this example ,(and many tutorial for CCSpriteBatchNode), they all needs to load all of these images to memory.

I can’t understand what is the benefit from a CCSpriteBatchNode…

Could anyone give me some inspiration?

Thanks

CCSpriteBatchNode is like a batch node: if it contains children, it will draw them in 1 single OpenGL call (often known as “batch draw”)

The above was found on the Cocos2d-x reference for CCSpriteBatchNode:
http://www.cocos2d-x.org/embedded/cocos2d-x/dd/d95/classcocos2d_1_1_c_c_sprite_batch_node.html

Yeah, I have seen this reference.

But I would like to know what is the critical difference between “drawing a bigger texture at once” with “drawing smaller textures with multiple OpenGL function call”?

The only difference that I can prospect is that if many images(sprites) are overlapped with each other, drawing at once can omit these overlapped parts of image.

Am I right?

Thanks!

So… to reword your question: Why is batch rendering faster than non-batch rendering?

Random Google search reveals

To draw an object on the screen, the engine has to issue a draw call to graphics API (OpenGL ES in case of iOS). Every single draw call requires a significant amount of work to be executed inside the graphics API. Therefore, each draw call causes significant performance overhead on the CPU side.

Fewer draw calls == fewer overhead.

Although I’m no OpenGL guru, for overlap I do not believe that your assumption is correct unless you are using some specific parameters. You may want to look into depth testing for that.

Thanks for your reply!

Originally, I think OpenGL call don’t cause significant overhead, and it might be a wrong assumption.

I believe that I will do some experiment and test about it after I finished the prototype of my game.

Thanks a lot.

Id recommend using batch node when ever you can!

Our game is coming from iOS to android as well, at least on iOS, our game came from an average of 35/45 fps to full 60 fps just from using batch node, we have at least more then 60/90 sprites and we use 4 spritesheets, 1024x2048, 1024x1024, 2048x2048, 1024x2028, and as you can see, we are using way too much memory just by loading this textures, but we managed to pack all of our sprites to their respective spritesheet images and reduce the memory size by using 4444 bits textures. And when they were grouped together (using parallax + few batch nodes) we had a huge performance boost!

If your game does not use a lot of draw calls or you are just testing it out, then there is a chance that you wont fell a difference. But when things start to get big, you should optimize whenever you can.

Sorry about the english! :slight_smile: