Skip to content

Cocos/Laya/Egret Engine Adaptation ​

Support Status ​

Many developers are very concerned about how minigames support game engines such as COCOS, Egret, and Laya. However, a minigame is a JavaScript runtime environment different from a browser, without BOM and DOM APIs. Yet almost all HTML5-based game engines rely on the BOM and DOM APIs provided by the browser. Therefore, to use an engine in a minigame, the engine must be modified.

Currently, COCOS, Egret, and Laya have completed the adaptation and support of their own engines and tools for minigames, and their official documentation already covers minigame development integration.

A Minigame Is a Runtime Environment Different from a Browser ​

Regardless of the engine, most of what is ultimately done while a game runs is updating the screen and playing sounds in response to user interaction. The development language of a minigame is JavaScript, so at the engine's lower level, drawing APIs and audio APIs need to be called through JavaScript.

The APIs a piece of JavaScript code can call at runtime depend on the host environment. Even the console.log we use most often is not part of the JavaScript language core, but is provided by the browser host environment. Common host environments include browsers and Node.js. Browsers have BOM and DOM APIs, whereas Node.js does not; Node.js has file and network APIs provided by core Node.js modules such as fs and net, which browsers lack.

Therefore, the minigame runtime environment is a host environment different from a browser. It does not provide BOM and DOM APIs; instead it provides the OpenPaaS API. Through the OpenPaaS API, developers can invoke the drawing, audio/video, network, file, and other capabilities provided by Native.

For example, if you want to create a canvas, you need to call:

JS
 Canvas sud.createCanvas()

Therefore, almost no HTML5-based game engine can be migrated directly to a minigame, because engines more or less use BOM and DOM APIs specific to the browser environment. Only by modifying the engine to change calls to BOM and DOM APIs into calls to the OpenPaaS API can the engine run in the minigame environment.