Turn COCOS2DX memory optimization

Source: Internet
Author: User

COCOS2DX inside, the sprite itself does not consume much memory, only the associated material files consume memory. Suppose there are 10 sprites associated with the same material, and no more than 10 times times the consumption.


As for the memory of the material used in the image, I think there are several optimization methods:
1, for the background map, because there is no need to consider the issue of transparency. The RGB565 format can be used when loading materials (5-bit red, 6-bit green, 5-bit blue), and the memory consumed by each pixel is 16bit = 2byte. Consumes less than half the memory consumed by the default RGBA8888.
2, the large size of the picture can be suitably reduced, the display of stretching and amplification. For example, 960x640 's figure can be reduced to 768x512, consuming less than half of the memory.
3, some sprites do not need so much color, can be loaded in RGBA4444 format, a pixel also consumes only 2byte, reduce half. You can use tools such as texturepacker to process raw 32bitpng images and generate RGBA4444-formatted material files.
4, a number of small pictures merged together, made of sprite sheet, can significantly reduce memory usage, performance will be better.
5, the large background map is cut into a number of small pieces, you need to show which area to load the corresponding block. The program is a lot more complicated, but it's better than the memory crash.

The above optimization method, I personally practice the effect is still very obvious.

1. OpenGL generally uses 2 of the N-square map size, so make the map as close as possible to 2 of the nth square value, such as 128*128. If you have a tile with a map size of 130*100, try to rearrange the slices so that it is within 128*128, which can reduce the memory by half.
2. You can use the small image to enlarge to paste, but I suggest that for the background map so, when the clarity requirements are not high, the size of the whole number of times to reduce the map, and then the map using nearest near the difference algorithm, so that the effect is acceptable, high efficiency.
3. When you are compositing a slice, be careful to put together slices with the same timing and frequency, so that the map that is currently loaded into memory is the most frequently used. The stickers that are not currently in use should be released in time. Gamers can generally accept waiting for a progress bar to load something.
4. Pre-game can be used simulator test, the late must be real machine +instruments test, Xcode instruments function is very strong, can detect LEAK,OPENGL optimization recommendations, allocation and so on.
5. Game caution avoid repeatedly allocating memory in logic loops or render loops, resulting in vicious growth.
6. PNG to use PS for the Web compression, you can reduce the file size, although not reduce the runtime memory allocation, but can reduce the map load IO time

Turn COCOS2DX memory optimization

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.