Use of COCOS2DX auto-batching

Source: Internet
Author: User
Tags addchild

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

    1. Make sure the sprite has the same Textureid (Sprite form Spritesheet)

    2. Make sure you have the same material and blending capabilities

    3. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.