Publish Time:2024-12-01
The code consists of engine and business logic code, with the engine taking up more space. Engine optimization is simple - remove unused modules, and avoid using modules that take up large space if possible.
usiness logic code generally can't be modified, but 95% of developers overlook an important point: setting.js. The size of setting.js is determined by the number of files in the resources folder. Resources not loaded by code should definitely be placed outside the resources module.
elow are the engine modules and their descriptions for reference:
Module | Description | Size |
---|---|---|
Core | Required | - |
Canvas | Required, canvas | - |
Sprite | Required, sprite | - |
Label | Required, text control | - |
Audio cc.audioengine | Singleton object, mainly used for playing audio | 11k |
AudioSource | Audio source component, can clip audio | 2k |
Action | Behavior animations | 55k |
Animation | Animations | 26k |
Button | Buttons | 11k |
Collider | Collision | 8k |
Dynamic Atlas | Dynamic texture atlas/batching | 5k |
DragonBones | DragonBones animation | 234k |
EditBox | Input box | 21k |
Graphics | Drawing interface | 21k |
Geom Utils | API for 3D collision detection (ray) | 31k |
Intersection | Collision system detection helper class | 2k |
Layout | Layout component | 12k |
LabelEffect | Text effects (outline, shadow...) | 2k |
Mask | Mask component | 8k |
Mesh | Mesh | 13k |
MotionStreak | Trail effect | 4k |
NodePool | Object pool | 0.7k |
Native Socket | Network module (XMLHttpRequest), adding this module actually reduces package size by 8 bytes | -8byte |
Physics | Physics module | 384.7k |
PageView | Page view container | 6.72k |
PageViewIndicator | Page view indicator component | 1.73k |
ProgressBar | Progress bar | 2.57k |
ParticleSystem | Particle system | 59.6k |
RichText | Rich text | 15.9k |
RendererTexture | Resource type, can be used for screenshots, has reference relationship with cc.Label, recommended to enable | 5k |
Slider | Slider | 3byte |
ScrollBar | Scrollbar | 3.85k |
ScrollView | Scroll container | 19.94k |
SpineSkeleton | Spine animation | 183k |
StudioComponent CocosStudio | Editor project file support | 555byte |
Toggle CheckBox | Checkbox component | 4.9k |
TiledMap | Display TMX format maps | 49.3k |
VideoPlayer | Video component | 12.99k |
Widget | UI layout component (commonly used) | 6.84k |
WebView | Internal page interaction view | 6.9k |
3D | 3D core module | 35.144k |
3DPrimitive | Utility class for creating basic 3D model vertex data | 19k |
cannon.js | Open-source physics engine developed in JavaScript with comprehensive physics simulation | 192k |
Builtin | Physics engine for collision detection system. Compared to other physics engines, Builtin has no physics simulation but advantages in smaller package size and computation | 38k |
3DParticle | 3D particle effects | 193k |
SafeArea | Component that adapts node layout to safe areas on phones like iPhone X, compatible with Android and iOS, typically used for top-level UI interaction nodes | 906byte |
JPG format images are smaller than PNG; after exporting art, use TinyPNG tool for compression; image resolution of 960x540 is sufficient, consider reducing resolution if higher
Use 9-slice images instead of full images when possible to greatly reduce image resolution and save resources
Image clarity: Adjust quantization coefficients for PNG images to reduce key information clarity without changing resolution, achieving resource savings
Image pixel format: Use ARGB4444 format for color images
After sprite atlas packing, organize and adjust empty spaces to reduce whitespace
Minimize frame animations, or replace them with skeletal animations to save resources
Recommend using MP3, OGG formats for audio effects
Stereo audio is twice the size of mono; can reduce size by adjusting sampling rate to 44100 samples per second using compression software or video encoding tools
Background music is usually larger, prioritize optimizing background music size
Use bitmap fonts for special effect text when possible - a few letters + images are much smaller than a complete font library and perform better
Use system font libraries when possible
Use fontmin tool to compress font libraries by removing unused characters to reduce size
Bitmap fonts are faster but use more memory; vector fonts are slower but use less memory