Cocos2d-x iOS game development (vi) Optimization of rendering

Source: Internet
Author: User
Tags addchild

The development of the program must take into account the memory optimization, after all, the memory of the iphone itself is not very large. This section mainly describes the cocos2d development of memory optimization, detailed table now, both can be the same sprite (picture) only once, but also can be rendered only once for the genie.

The following is the procedure of the program, first block the previous code.

let me introduce you.Ccspritebatchnode optimize game rendering efficiency. in >ccspritebatchnode " Span style= "Color:rgb (204,0,0); font-family:arial; line-height:20px ">ccsprite will only be rendered 1 times, so the game's FPS can be improved. Limit: Increase to Ccspritebatchnode ccsprite must use the same texture map.

Detailed code

ccspritebatchnode *node =ccspritebatchnode::Create(" Peashooter1.tiff "); // render the file first

This,addChild(node);

ccsprite *plant = ccsprite::create ("Peashooter1.tiff"); // Creating Sprites

Plant->setposition (CCP(a));

Node->addchild (plant); // added to node in

Perform:


Can see Adding a genie at this time the fps is 1. The following again adds a file to the same wizard:

ccspritebatchnode *node =ccspritebatchnode::Create(" Peashooter1.tiff "); // render the file first

This,addChild(node);

ccsprite *plant = ccsprite::Create("Peashooter1.tiff"); // Creating Sprites

Plant->setposition(CCP(a));

Node->addChild(plant); // added to node in

// Create a sprite again

ccsprite *plant1 = ccsprite::Create("Peashooter1.tiff"); // Creating Sprites

Plant1->setposition(CCP(+));

Node->addChild(plant1);

return true;

Perform:


You can see that two sprites have been created, but fps is still 1. This is the role of Ccspritebatchnode, which guarantees that all the same files that are added to the class are rendered only once.


Since the same elves can only render. Then the wizard of different files can not be rendered only once, the answer is yes. Look at the following procedure.

This is to use the content of article (v). The detailed approach is that we are able to synthesize a large image of very many different images and then add this large image to the Ccspritebatchnode. In this case, the small map inside the rendering large image will be rendered only once, see the detailed procedure practice:

     ///* assumes that you want different images to render only once to use the frame caching mechanism render multiple different pictures */

    ccspriteframecache :: sharedspriteframecache ()-> Addspriteframeswithfile ( "person.plist" // First cache large image

ccspritebatchnode *node1 =ccspritebatchnode::Create("person.png "); // render to a large picture

This,addChild(Node1);

ccspriteframe *frame =ccspriteframecache::sharedspriteframecache ()spriteframebyname(" png");

ccsprite *plant3 =ccsprite::createwithspriteframe(frame);

Plant3->setposition(CCP);

Node1->addChild(PLANT3);

ccspriteframe *frame1 =ccspriteframecache::sharedspriteframecache ()spriteframebyname(" login . png");

ccsprite *plant4 =ccsprite::createwithspriteframe(frame1);

Plant4->setposition(CCP);

Node1->addChild(PLANT4);

The name of this large map all small picture:


Perform:


We were able to see two more pictures added. And the two pictures are not the same, but fps or 2 only added 1, indicating that the newly added two sprites have only been rendered once, and now we find that the frame caching mechanism is very powerful, in the game development is often used.


Cocos2d-x iOS game development (vi) Optimization of rendering

Related Article

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.