New features of auto-batching in cocosdx3.0+ based on official documents what does this thing do?
We know that in our game development, we often encounter a lot of the same sprite on the screen (such as a large group of soldiers in LOL) and according to our experience, we can see that it will be rendered once during the loading wizard. Do we need to render each sprite multiple times each time we want to load a large number of the same sprites?
Official documentation Note Auto-batching (automatic batching) takes effect to meet the following conditions
Make sure the sprite has the same Textureid (Sprite form Spritesheet)
Make sure you have the same material and blending capabilities
cannot be added to Spritebatchnode again
In short, if we use the same picture to create the Genie, and we can satisfy the condition without special treatment.
But there are some things to note:
for (int i =0;i<10000;i++)
{
Auto A = sprite::create ("Sprite1.png");
This->addchild (a);
Auto B = sprite::create ("Sprite2.png");
This->addchild (b);
}
Because we created two sprites in a loop every time, although the same picture is used for the A and B sprite loops, the load in memory is two picture intervals rendered as follows:
Sprite1
Sprite2
Sprite1
Sprite2
Sprite1
Sprite2
。
。
。
Sprite1
Sprite2
This situation does not meet the requirements of auto-batching
So what can we do about it?
for (int i =0;i<10000;i++)
{
Auto A = sprite::create ("Sprite1.png");
This->addchild (a);
A->setgloblezorder (1);
Auto B = sprite::create ("Sprite2.png");
This->addchild (b);
B->setgloblezorder (1);
}
In memory, the following conditions occur:
Sprite1
Sprite1
Sprite1
Sprite1
Sprite1
Sprite1
。
。
。
Sprite2
Sprite2
Sprite2
Sprite2
Sprite2
Sprite2
The conditions of auto-batching are met at this time.
Use of COCOS2DX auto-batching