Blue ou iOS training recommendations: some time ago I had organized an article on Cocos2d-x nodes and rendering tree content, so today and everyone to share something really a little similar and close to it! What we need to learn today is how Cocos2d-x uses CCSpriteBatchNode to improve rendering efficiency? If you are interested, you can learn it as a reference!
So less talk, directly go to the Introduction interface, previously introduced to you the cocos2d-x of the relevant content, have seen the lower left corner of the FPS has become 3 lines, there are two more rows of data.
The top line refers to the rendering batches of the current scene. You can also understand how many textures need to be rendered. The middle line is the time required to render each frame, the lowest level is the FPS that everyone is familiar ).
The following describes CCSpriteBatchNode:
1. First of all, let's talk about the important optimization indicators of the rendering batches.): it refers to a rendering. This means that the fewer rendering times, the more efficient the game is.
2. CCSpriteBatchNode is a specialized management sprite class built by the cocos2d-x to reduce rendering batches.
For example:
1、use ccspriteto create 1000 icon.png in the scene. In this way, the rendering batch is. Here, no other elves are considered.
650) this. width = 650; "title =" inline "src =" http://www.bkjia.com/uploads/allimg/131229/12200023O-0.jpg "alt =" 150437926.jpg"/>
As shown in the preceding figure, 1000 icons are created in the scene, so that the FPS is 22 and the rendering batch is 1000.
2. Use CCSpriteBatchNode for batch rendering, and draw all CCSprite in one rendering. Significantly reduce rendering batches.
For example:
1、use ccspriteto create icon.png files in the scene, but CCSpriteBatchNode is used for batch rendering. What is the rendering batch and FPS?
650) this. width = 650; "title =" So fpswill be .jpg "src =" http://www.bkjia.com/uploads/allimg/131229/12200042c-1.jpg "alt =" 150527432.jpg"/>
The following figure shows the output result:
650) this. width = 650; "title =" let's look at the following figure, then the output result. jpg "src =" http://www.bkjia.com/uploads/allimg/131229/1220002618-2.jpg "alt =" 150616427.jpg"/>
From this we can see that 1000 icons are created in the scene. The FPS is 39.9, and the rendering batch is 1.
Pay attention to the following points:
1. CCSpriteBatchNode: create (constchar * fileImage); // create with texture. The default number of child nodes is 29. CCSpriteBatchNode * batchNode = CCSpriteBatchNode: create (constchar * fileImage, unsignedintcapacity); // create with a texture and specify the number of child nodes.
2. When using CCSpriteBatchNode, the image to be pasted must be the same image, and the depth of the Genie cannot be specified. All genie must be on the same rendering layer.
3. However, it is impossible for a project to always be on a texture. Therefore, you can combine several textures into a large image. Then we need to create a CCSpriteBatchNode with the merged large texture. When creating CCSprite, you can set the texture area.
So it's basically so much. I don't know if you can understand it? If you have any questions, please feel free to ask me. I am very glad to help you. As a young man of the 21st century, he must have a progressive mentality.