1. ccspritebatchnode is implemented to improve rendering efficiency. It inherits from ccnode
2. FPS: frame rate, which is a very important concept in the game to balance the smoothness. In Cocos, the default frame rate is 60, that is, 60 frames are refreshed in one second.
3. How genie sets work:
The images to be rendered in advance are loaded to the memory using batchnode. When needed, they are directly extracted from the memory, saving the loading process and thus high efficiency.
If you want to load 1000 gems, load and render the files and execute them 1000 times. Use ccspritebatchnode for batch rendering, and draw all ccsprite in one rendering. Significantly reduce rendering batches.
4. steps:
A. First load the sprite image to be rendered multiple times into batchnode (equivalent to using batchnode for pre-loading)
B. Load the batchnode TO THE cclayer to be used.
C. You need to use a certain genie (provided that it has been loaded in batchnode ).
5. Code implementation:
Load an image:
/* Create a ccbatchnode object to render the image resource you want to use in advance */batchnode = ccspritebatchnode: Create ("batchnode/closenormal.png"); addchild (batchnode ); // load the batchnode into cclayerbool t06spritebatchnode: cctouchbegan (cctouch * ptouch, ccevent * pevent) {for (INT I = 0; I <1000; I ++) {ccsprite * SPR = ccsprite: Create ("closenormal.png"); // normal, the image has been rendered in batchnode in advance SPR-> setposition (CCP (ccrandom_0_1 () * 480, ccrandom_0_1 () * 320); batchnode-> addchild (SPR); // Add it to batchnode for rendering.} return false ;}
Load multiple images:
/* Use batchnode to load multiple images. plist */ccspriteframecache: sharedspriteframecache ()-> addspriteframeswithfile ("batchnode/plant. plist "); batchnode = ccspritebatchnode: Create (" batchnode/plant.png "); addchild (batchnode); // load the batchnode into cclayerbool vertex: cctouchbegan (cctouch * ptouch, ccevent * pevent) {static bool flag = true; ccsprite * SPR; For (INT I = 0; I <1000; I ++) {If (FLAG) {SPR = cc Sprite: closenormal.png ("closenormal.png"); // these images must have been previously smoked in batchnode.} else {SPR = ccsprite: createwithspriteframename ("icon.png ");} flag =! Flag; SPR-> setposition (CCP (ccrandom_0_1 () * 480, ccrandom_0_1 () * 320); batchnode-> addchild (SPR );); // Add it to batchnode for rendering.} return false ;}
Use of the batchnode Genie set in cocos