In Wings Engine, each custom development file should be a JS class. Even if the code does not explicitly extend the Extension class, it will implicitly extend Extension at runtime.
The Extension class has four lifecycle functions: init, ready, update, and destroy.
1 | class Button { |
The initialization functions include init and ready. Typically, initialization code is written in init. However, if the initialization depends on other components being initialized first, it should be written in ready, because the ready function is called only after all component init functions have been executed.
The update function is used to implement various animation effects. In Wings Engine custom development, this function is called once per frame render. Heavy computations should not be placed in this function to avoid severe performance issues. It is recommended to precompute resource-intensive calculations in the init function and simply call them in the update function.
If large arrays or other resources are created in the init or update functions, they must be cleared in the destroy function. For example, set the length of arrays to 0 or call the clear method on Maps, etc.
For a detailed introduction to the lifecycle functions, refer to the API documentation: https://shanhaibi.yuque.com/staff-uev5km/wings-engine/yshl32ezom1x6733