CCSpriteBatchNode performance vs CCSprite

Hi!

I’ve been trying to use CCSpriteBatchNode to improve the rendering speed of large numbers of identical sprites, but I’m not seeing any performance increase when I use it.
I’ve tried creating 20x100 sprites, but my framerate drops from 30 to 9, and the performance is identical regardless of which method I use.
Could I possibly be doing something wrong here?

//*************************************************
//METHOD 1: STANDARD SPRITE CREATION

for
{
for
{
//Loop create 20 x 100 sprites, add them to scene.
CCSprite* character_sprite = CCSprite::create;
character_sprite~~>setPosition);
this~~>addChild;
}
}

//*************************************************
//METHOD 2: BATCH NODE SPRITES

//Initialise texture and batch
CCTexture2D *texture = CCTextureCache::sharedTextureCache()>addImage;
CCSpriteBatchNode batch = cocos2d::CCSpriteBatchNode::createWithTexture;
//
for
{
for
{
//Loop create 20 x 100 sprites, add them to CCSpriteBatchNode.
cocos2d::CCSprite
character_sprite = cocos2d::CCSprite::createWithTexture);
character_sprite
>setPosition(ccp(i*10,j*10));
batch~~>addChild;
}
}
this~~>addChild(batch);

I would feel that 2000 sprites really shouldn’t kill performance that much: I don’t have anything else in the scene, so I’m wondering if it could be an issue with the way I am calling the sprite batch?
Any suggestions or thoughts would be most welcome: thanks in advance! :slight_smile:

At initial glance that looks about right. Where exactly is that code run, ie, in some init() function?

Loic Argelies wrote:

At initial glance that looks about right. Where exactly is that code run, ie, in some init() function?

Yes, it was run at init.
I think I’ve figured out what the problem was— it’s with overdraw. Despite being 10px apart, overdraw really seems to completely performance.
If I increase the spacing, the framerate goes up.

Hmm… I can’t see why that would be the case. What device are you running this on? If on mobile, i assume you have checked on device rather than on simulator to verify behaviour still holds?
In my experience, batching does help significantly, due to the texture draw calls drastic reduction. Without too much context, i’d start looking either on openGl compatibility or device vs/ simulator, and whether you have other things running on these sprites that would affect framerate (like CCActions, position tests, etc).

I’m running this on a PC, and my stats for 200x200 sprites are as follows:

  1. With overdraw, using CCSprite
    for (int j=0; j<200; j++)
    for (int i=0; i<200; i++)
    CCSprite* horse = CCSprite::create(“Horse.png”);
    horse->setPosition(ccp(200 ,200)); // All positioned at 200,200

*************** Batch count 40000, FPS: 8.5 average //SLOW
2) Without overdraw, using CCSprite
for
for
CCSprite
horse = CCSprite::create;
horse~~>setPosition); //All spaced out
*************** Batch count 40000, FPS: 6.1 average //SLOW
3) With overdraw, using CCSpriteBatchNode
for
for
CCSprite
horse = CCSprite::createWithTexture);
horse->setPosition); // All positioned at 200,200
*************** Batch count 1, FPS: 9.3 average //SLOW
4) Without overdraw, using CCSpriteBatchNode
for
for
CCSprite
horse = CCSprite::createWithTexture);
horse~~>setPosition); //All spaced out
**************** Batch count 1, FPS: 60.0 average //FULL SPEED!

It’s curious behaviour, though I can live with it :slight_smile: You guys might want to check it out though: if you directly copy my code, it should be very simple to replicate.
I’m using the default alpha blending. Is there any other blending mode which is faster but retains single colour transparency?

I found the same problem.

Also I checked test samples in Perfomance section.
There is no difference in fps between only sprites and batchnode in this test. It’s very strange.

1 Like

Any update on this topic ?