How to optimize cocos2d-x3.2 game memory in Cocos2d-X, cocos2dx3.0

Source: Internet
Author: User

How to optimize cocos2d-x3.2 game memory in Cocos2d-X, cocos2dx3.0

There will be a problem in game project optimization. How can we reduce both the memory size and the package size as much as possible? In actual projects, some experiences are shared. In fact, the most memory occupied by 2D games is image resources. The performance of a single image varies greatly with different texture formats, the following table shows the test results in a small Demo on the IOS platform. The original memory usage of this Demo is 7 MB, and the test method is to load 5 2048*2048 images at a time, use the TexturePacker tool to generate images. Use the Instrument tool for memory statistics. Use the CCTime class provided by the-X engine for loading time statistics, in microseconds.

Memory usage remarks for image format loading time
Png 782080 88 M 5 sheets 2048*2048 PNG
Pvr. ccz (POT) 394769 102 M 5 sheets 2048*2048 pvr. ccz (POT: The power of 2)
Pvr. ccz (NPOT) 338099 85 M 5 2047*1680 pvr. ccz (NPOT: not the integer power of 2, that is, the actual size of the graph)
Pvr (PVRTC4) 8875 33 M 5 sheets of 2048*2048 pvr (PVRTC4: lossy compression with a compression ratio of, the actual test shows that the image quality is basically no loss)

Conclusion:
1) Compare loading speed: the original PNG is the slowest, and the POT pvr is used. ccz is about 50% of the original PNG, using NPOT pvr. ccz is about 43% of the original PNG, and only 1% of the original PNG is needed when pvr is used;
2) memory usage: The pvr. ccz of POT is about 1.2 times that of the original PNG. pvr. ccz of NPOT is similar to that of the original PNG. only 40% of the original PNG is used for pvr;

We can see that when selecting the texture format for a large image, PVR is the most preferred, followed by NPOT pvr. ccz, taking into account multi-platform support and integration, the management solution for image resources can be as follows (the image size is based on iPad HD ):
1) PNG is still used for small images of 1024*1024 and below, because it is simple and can be used on all platforms;
2) For images larger than 1024*1024, pvr is preferred. It can be directly loaded into the display memory of IOS devices, so it is fast without memory resolution. However, sorry 1: android devices do not support this feature. Unfortunately, TP does not support generating pvr of 2048*2048 or above;
3) as described in section 2, NPOT pvr is used for 2048*2048 images and Android devices. ccz, in Cocos2d-x 2. by default, the x engine is supported. All ios settings after the 3-generation (iphone 3GS) Support cocos2d 2.x( because they support OpenGL ES2.0), so NPOT textures are also supported;
4) after testing, Android devices also support NPOT, so the solution is relatively simple. PNG is used for 1024*1024 and below, and pvr. ccz is used for 1024*1024 and above;

After the above scheme is adopted, the memory occupied by the game has been reduced from more than 90 M to more than 60 M, and it has been run on various IOS devices. touch3, tou4, iPad1, and other low-end devices are okay.


Don't understand can add my QQ group: 239982941 (cocos2d-x 3. x Learning Group) Welcome to your arrival Oh, read the blog to some footprints Bai, thank you ~~

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.