Understanding of COCOS2DX 3.x Sprite and Spritebatchnode

Source: Internet
Author: User
Transferred from: https://github.com/fusijie/Cocos2d-x3.0-Release-Note/blob/master/cocos2d-x_v3.0_release_notes.md# User-content-sprite-%e5%92%8c-spritebatchnode Sprite and Spritebatchnode

The recommended optimization game in v2.2 2.2 is to set the Spritebatchnode object as the parent of the Sprite object. Although using the Spritebatchnode object is still a good way to optimize the game, it still has some limitations: the child of the Sprite object can only be a sprite (otherwise, cocos2d-x will trigger the assertion) when the parent of the sprite is Spritebac Tchnode, you cannot add particlesystem as a child of a sprite. This will cause when the parent of the sprite is Spritebatchnode, you cannot use Parallaxnode all Sprite objects must share the same texture ID (otherwise, COCOS2D-X will trigger the assertion) the Sprite object uses Spritebat Chnode's mixed functions and shaders.

Although v3.0 still supports Spritebatchnode (with the same effects and limitations as previous versions), we do not encourage the use of it. Instead, we recommend that you use the Sprite directly, and you don't need to add it as a child node to Spritebatchnode.

However, in order for v3.0 to perform better, you have to make sure that your Sprite object meets the following criteria: Contribute the same texture ID (put them in a spritesheet, just like with Spritebatchnode) Make sure they use the same shader and blending functions (just like with Spritebatchnode)

If you do this, Sprites will be as fast as using Spritebatchnode ... (probably 10% slower on the old device and basically undetectable on the new device)

The biggest difference between v2.2 and v3.0 is that a Sprite object can have a different texture ID. Sprite objects can have different kinds of node as child nodes, including Particlesystem. Sprite objects can have different mixing functions and different shaders.

But if you do, the renderer may not be able to batch all of its child nodes (with lower performance). But the game still works, and no assertions are triggered.

Summary: Keep all the Elves in a big spritesheet. Use the same blend function (using the default) using the same shader (using default) do not add sprites to Spritebatchnode

Only if you need some extra performance boost (albeit small), Spritebatchnode will be your last choice (you need to be familiar with its limitations).

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.