Cocos2d Study Notes (2) ccspritebatchnode

Source: Internet
Author: User

Speaking of cocos2d, You Have To Say ccspritebatchnode


Benefits of using ccspritebatchnode:

1. Reduce the bind Call of OpenGL ES. Here we will briefly describe the loading of slice. When an image is to be displayed, it will first be converted to texture and then loaded into the memory, because most GPUs know the extracted images (PNG is a compressed image, GPU can also process some compression formats, such as pvrtc), and then draw this image to the screen through OpenGL ES. When a scene loads a large number of images, it is bound to call OpenGL ES multiple times, in this way, the GPU will be under great pressure and the number of frames will fall. UseCcspritebatchnode can load all the images in the current scenario at a time to reduce a large number of GPU operations, and the number of frames naturally increases.

2. Reduce memory usage. In fact, this is not the most important now, because all devices later than 3gs support npot (Non power of two. When the old GPU saves texture, it can only store the size of power-of-two, that is, the size of all your images is 50x50 pixels, and the final size is 64x64 in the memory.
* 64-50*50 memory is a waste (in fact, the CPU and GPU operation image memory address are not one, so when the GPU operates the image, this image will also be tested in the memory area that can be operated by the GPU, so that part of the wasted memory will be copied again ). You don't have to worry about this when using texture atlas,Texture Atlas allows you to put images one by one and load them into the memory at a time, which greatly reduces the memory consumption of each image. However, in cocos2d1.1, npot is automatically enabled as long as the device supports npot. The current version is 1.0.0. In ccconfig. H, we can see that:

 @ DeprecatedThis value will be removed in 1.1 and npot textures will be loaded by default if the device supports it.

So how important is the development of science and technology, so we need to consider less and less, haha!


In fact, the most important thing is the first article.


The easy-to-use software for creating texture Atlas is texturepacker. I will not release the link. I will find this on the Internet.


Ccspritebatchnode is also easy to useFirst, use ccspriteframecache to load the frame file ([Ccspriteframecache sharedspriteframecache] addspriteframeswithfile: @ "scene1atlas. plist"]), Is a plist file, using texturepacker to create texture
It is automatically generated during Atlas, and then [Ccspritebatchnode batchnodewithfile:@ "Scene1atlas.png"] Ccspritebatchnode object and add it to cclayer. Then ccsprite creates an object through-(ID) initwithspriteframe :( ccspriteframe *) spriteframe, and finallyCcspritebatchnode object
Addchild:Ccsprite objectYou can.


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.