Cocos2d-lua performance optimization (Tencent Game Academy)

Tencent Game Academy-Optimize Cocos2d-x game performance

Some commonly used optimization methods in Cocos2d-x

  1. Use Batch Draw as much as possible

  2. According to experience, try to control the number of your draws below 50

  3. Reduce the use of 32-bit uncompressed textures and try to use 16-bit compressed texture formats. Texture compression

  4. Use compressed textures that support hardware decoding as much as possible: For example, the iOS platform uses PVRTC textures, and the Android platform uses ETC format textures. At present, all Android devices support textures in ETC1 format, but this texture format does not support Alpha, so you need to modify the engine to use textures in ETC1 format.

  5. Do not use system fonts to dynamically display information such as scores in your game, please use BMFont fonts.

  6. Please use object pooling and preloading techniques to avoid temporary freezes.

  7. Use armeabi-v7a architecture to compile Android's SO, because under this architecture Cocos2d-x will enable neon instruction set, the efficiency of matrix operations will be greatly improved.

  8. Don't use dynamic lighting, try to use bake lighting.

  9. Avoid doing very complicated calculations in the pixel shader

  10. Avoid using discard and alpha test in the pixel shader, because this will destroy the GPU's own depth testing optimization, such as PowerVR's HSR.

  11. Use texturepacker to puzzle, use texturepacker to pack some small scatter images into a big image, reduce texture IO and draw call.

  12. Use the object pool, and use the object pool in scenes that require frequent creation of objects.

  13. Release useless textures when switching scenes
    CCTextureCache:sharedTextureCache():removeUnusedTextures();
    CCTextureCache:sharedTextureCache():dumpCachedTextureInfo();

  14. Organize resident memory UI resources, package the interface resources such as the common menu at the bottom of the main interface into a texture, resident memory, save the overhead of loading and recreating textures

  15. Pre-loading method, for external resources that need to be used in the game, such as texture atlas, sound files, and TTF files, try to use the pre-loading method to process.


Performance optimization:
1 Entry animation/loading in frames to avoid too much processing of one frame <lineup exit animation>
2 Delayed release (in popScene, because it will freeze when switching scenes/recycling for a moment)
3 Preload resources (ie , crop ahead) Into memory, sound effects/spine/...)
Low-end machine lag optimization (like iphone5 memory 512M): set texture format (memory) / no special effects... / clear unse texture and spine / delete preload (combat interface)


Programming basics:
repeated use of for loops or regular expression data-driven (abstract the data as an array or a table)


Adaptation principle:
1 When the anchor point x is set to 0 and position=0 on the left side of the screen. The anchor point is set to 1 when the screen is on the right side, and the position = screen width
2. The position is relative to the upper layer/parent node,

Insert picture description here
Insert picture description here

-------Some bug feedback

bug.
A Black Shark’s story show will lose voice processing
. B. Black Shark’s mobile phone show will play voice and mouth shape is out of sync.
Analysis: The lack of synchronization is due to the delay in playing the voice – preloading)
Single model error: Normally not Will be processed for a certain model / at most classifications (such as low-end machines in Vietnam, high-end machines) unified processing


Project foundation: (Lecture)
1 UI specification
2 Code specification
3 Code general component
4 Convenient debugger
5 Function module (data UI logic...)
Insert picture description here

Guess you like

Origin blog.csdn.net/u013321328/article/details/108793253