Well, today we have nothing to do. It hurts to be idle. Let's just create an genie to play. I just hit it. I went there and made 10 thousand genie. I felt like a omnipotent god, 10 thousand (Narrator: please do not give up the treatment), hey, look at what the 10 thousand genie looks like:
It looks very good (Narrator: Wait, how did the number of frames fall so much), the amount was actually seen by my sister paper. Okay, let's go to today's course.CCSpriteBatchNode
<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + 1 NrTzs + examples/JxNy74bTzwb + examples/nS1Nahyv2yu7/examples + HB9LW91 + 6687XE "advanced ), the most intuitive effect in the game is choppy. To solve this problem, cocos2dX introduced CCSpriteBatchNode to us. Let's take a look at the magic of CCSpriteBatchNode.
By the way, let me explain the three rows in the lower left corner:
The first line: the rendering batches of the current scenario, which can be simply understood as the number of genie drawn in the current scenario
Row 2: Time consumed by rendering each frame
Row 3: FPS, number of frames drawn per second
The smaller the rendering batches, the smoother the game, the smaller the FPS, And the choppy the game.
You can set display/hide in AppDelegate. cpp.
We recommend that you enable it during testing and hide it during release.
Let's take a look at the usage:
CCSpriteBatchNode * batchNode = CCSpriteBatchNode: create (image file, default number of subnodes );
First:
// Create a batch of rendering objects and add them to the current layer CCSpriteBatchNode * batchNode = CCSpriteBatchNode: create ("CloseSelected.png", 10000); addChild (batchNode); for (int I = 0; I <10000; ++ I) {CCSprite * sprite = CCSprite: createWithTexture (batchNode-> getTexture ()); // obtain the texture from CCSPriteBatchNode to create sprite-> setPosition (ccp (CCRANDOM_0_1 () * 480, CCRANDOM_0_1 () * 320 )); // obtain the random coordinate CCRANDOM_0_1 to generate 0 ~ 1-> addChild (sprite); // Add it to CCSpriteBatchNode}
Let's see if we have rendered an object, the frame rate is also running, and the game is no longer stuck. It is delicious and the body is superb (Narrator: Are you out of the air today)
Well, this is the end of today's lecture, but there are several points to note:
When CCSpriteBatchNode is created, the default number of subnodes is 29, but when the number is insufficient, it will increase by itself.
Only the same texture map can be used when CCSpriteBatchNode is used.
When CCSpriteBatchNode is used, zOrder cannot be specified, that is
Well, today seems to be a real day. If you have any questions/experiences, you may want to share them in the group:223856254