Use of the batchnode Genie set in cocos

Source: Internet
Author: User
Tags addchild

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

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.