tencent cloud

Tencent Cloud Super App as a Service

Release Notes and Announcements
Announcement: Tencent Cloud Mini Program Platform Renamed to Tencent Cloud Super App as a Service on January 2, 2025
Console Updates
Android SDK Updates
iOS SDK Updates
Flutter SDK Updates
IDE Updates
Base Library Updates
Product Introduction
Overview
Strengths
Use Cases
Purchase Guide
Billing Overview
Pay-As-You-Go Billing
Renewal Guide
Service Suspension Instructions
Getting Started
Plan Management
Overview
Console Account Management
Storage Configuration
Acceleration Configuration
Branding Configurations
Platform Features
Console Login
Users and Permission System
Mini Program Management
Mini Game Management
Superapp Management
Commercialization
Platform Management
User Management
Team Management
Operations Management
Security Center
Code Integration Guide
Getting Demo and SDK
Android
iOS
Flutter
Superapp Server
GUID Generation Rules
Mini Program Development Guide
Mini Program Introduction and Development Environment
Mini Program Code Composition
Guide
Framework
Components
API
Server Backend
JS SDK
Base Library
IDE Operation Instructions
Mini Game Development Guide
Guide
API
Server Backend
Practice Tutorial
Mini Program Login Practical Tutorial
Mini Program Subscription Message Practical Tutorial
Payment Practical Tutorial
Ad Integration Practical Tutorial
Mini Game Subscription Message Practical Tutorial
API Documentation
History
Introduction
API Category
Making API Requests
Operation Management APIs
User Management APIs
Team Management APIs
Sensitive API-Related APIs
Role Management APIs
Platform Management APIs
Other Console APIs
Mini Program or Mini Game APIs
Management-Sensitive APIs
Global Domain Management APIs
Superapp APIs
Data Types
Agreements
Service Level Agreement
Data Processing and Security Agreement
SDK Privacy Policy Module
SDK Data Processing and Security Agreement Module

Engine Adaptation

PDF
Focus Mode
Font Size
Last updated: 2025-03-25 18:15:55

Support for game engines

Mini games operate in a JavaScript runtime environment that differs from browsers, lacking BOM (Browser Object Model) and DOM (Document Object Model) APIs. Most HTML5-based game engines rely on these browser-provided APIs. Therefore, to use these engines in mini games, modifications are necessary.

Currently, engines like Cocos, Egret, and Laya have adapted their tools and engines to support mini games. Their official documentation provides guidance on integrating with mini game development.
Cocos
LayaAir
Egret

Mini games: A different runtime environment

Regardless of the engine, most tasks during game runtime involve updating the display and playing sounds based on user interactions. Since mini games use JavaScript, the engine's core must call drawing and audio APIs through JavaScript.
The APIs available to a JavaScript code depend on the host environment . For example, console.log console.log is not part of the JavaScript core language but is provided by the browser environment. Common host environments include browsers and Node.js. Browsers provide BOM and DOM APIs, while Node.js offers file and network APIs through core modules like fs and net. For instance, the following code runs in a browser but will throw an error in Node.js:
let canvas = document.createElement('canvas')
This is because document is not defined in the Node.js environment
ReferenceError: document is not defined
In mini games, the runtime environment does not provide BOM and DOM APIs but offers wx APIs. These APIs allow developers to access native capabilities for drawing, audio/video, networking, and file handling.

If you want to create a canvas, you need to call the wx.createCanvas()
let canvas = wx.createCanvas()
let context = canvas.getContext('2d')
If you want to create an audio object, you need to call the wx.createInnerAudioContext()
let audio = wx.createInnerAudioContext()
// The src address is for demonstration purposes and does not actually exist
audio.src = 'bgm.mp3'
audio.play()
If you want to get the width and height of the screen, you need to call the wx.getSystemInfoSync()
let { screenWidth, screenHeight } = wx.getSystemInfoSync()
In contrast, HTML5 game engines typically use:
let canvas = document.createElement('canvas')
let audio = document.createElement('audio')
console.log(window.innerWidth)
console.log(window.innerHeight)
This will result in errors because the mini game environment does not provide document and window global variables. Mini games operate in a JavaScript runtime environment that differs from browsers.
ReferenceError: document is not defined
ReferenceError: window is not defined
So, basically, all HTML5-based game engines cannot be directly migrated to mini games, as the engine may more or less use BOM and DOM APIs that are specific to the browser environment. To run these engines in the mini game environment, you need to modify the engine to replace BOM and DOM API calls with wx API calls.
Alternatively, you can add an adaptation layer, called an Adapter, between the engine and game logic. This Adapter simulates the necessary window and document properties and methods using wx APIs, making the engine unaware of the environment differences.

Adapter is user code, not part of the base library. For an introduction to Adapter, please see Adapter.

Use other game engines

If you want to use other HTML5 game engines not mentioned above, you can still develop mini games by modifying the engine. Start by introducing a general Adapter and then address issues as they arise.




Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback