Batch Sprite Node

Source: Internet
Author: User
Tags addchild

<title>Batch Sprite Node</title> Batch Wizard nodes when used in a lot of sprites, the use of batch processing can reduce the number of rendering times, improve efficiency, of course, when the number of sprites is small, there is no need to use batch processing
BOOL t02layers :: Init (){       if (! Cclayer:: Init ())       {               return false;       }        ccsize winsize = Ccdirector:: Shareddirector ()->getwinsize ();        Ccpoint Ptcenter = CCP(WINSIZE.WIDTH/2, WINSIZE.HEIGHT/2);
        /*Ccspritebatchnode is also a container, but it can only contain Ccsprite objects, and requires these sprites to come from the same texture       */
       Ccspritebatchnode* Batch = Ccspritebatchnode :: Create ("Closenormal.png" );addChild (batch);_batch = batch;
      Ccsprite* Sprite = Ccsprite:: Createwithtexture (Batch->gettexture ());Batch->addchild (sprite);
sprite->setposition (ptcenter);
settouchenabled ( true);Settouchmode ( Kcctouchesonebyone);       return true;}

BOOL t02layers :: Cctouchbegan (Cctouch* Touch, ccevent*){        ccsize winsize = Ccdirector:: Shareddirector ()->getwinsize ();        for ( int i = 0; i <; i++)        {               Ccsprite* Sprite = Ccsprite:: Createwithtexture (_batch->gettexture ());_batch->addchild (sprite);               //ccrandom_0_1() used to generate random numbers from 0 to 1, which is a defined macro Sprite->setposition ( CCP( ccrandom_0_1() *winsize.width, ccrandom_0_1() * winsize.height));        }        return true;}
Results:

If you do not use batch processing:


Three lines of numbers, the first line indicates the number of times the sprite is rendered the third line represents the number of frames in 1s, which is the number of refreshes.

From for notes (Wiz)

Batch Sprite Node

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.