Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

feat(wechat): carry the project camera fit into the mini-game runtime

yhh7aace28aa081
diff --git a/desktop/electron/exportGame.ts b/desktop/electron/exportGame.ts
index 27dea09a1..412245fba 100644
--- a/desktop/electron/exportGame.ts
+++ b/desktop/electron/exportGame.ts
@@ -327,6 +327,7 @@ export async function exportGame(opts: {
orientation,
ySortLayers: opts.ySortLayers,
colorSpace: opts.colorSpace,
+ screenFit: opts.screenFit,
minify: opts.minify,
contentAddressed: opts.contentAddressed,
compressTextures: opts.compressTextures,
diff --git a/desktop/electron/exportMiniGame.ts b/desktop/electron/exportMiniGame.ts
index 45c57ba66..9bd5f3cdb 100644
--- a/desktop/electron/exportMiniGame.ts
+++ b/desktop/electron/exportMiniGame.ts
@@ -222,6 +222,9 @@ export async function exportMiniGame(profile: MiniGameExportProfile, opts: {
ySortLayers?: number;
/** Project color space — 'linear' boots the mini-game on the linear-light pipeline. */
colorSpace?: 'gamma' | 'linear';
+ /** Project camera fit (Project Settings → Display) — letterboxes the design resolution
+ * without a UI Canvas; absent = no fit. */
+ screenFit?: { designWidth: number; designHeight: number; scaleMode: number; matchWidthOrHeight: number };
minify?: boolean;
/** Emit content-addressed asset filenames (<hash><ext>) for dedup + immutable caching. */
contentAddressed?: boolean;
@@ -337,7 +340,7 @@ export async function exportMiniGame(profile: MiniGameExportProfile, opts: {
`import { ${profile.runtimeInit} } from 'esengine';\n` +
(scriptsAbs && existsSync(scriptsAbs) ? `import ${JSON.stringify(scriptsAbs)};\n` : '') +
`export function boot(engineFactory, sideModuleFactories) {\n` +
- ` return ${profile.runtimeInit}({ engineFactory, engineWasmPath: ${JSON.stringify(engineWasmPath)}, sideModuleFactories, sceneNames: ${JSON.stringify(scenes.map((s) => s.name))}, firstScene: ${JSON.stringify(sceneName)}${opts.ySortLayers ? `, ySortLayers: ${opts.ySortLayers >>> 0}` : ''}${opts.colorSpace === 'linear' ? `, colorSpace: 'linear'` : ''} });\n` +
+ ` return ${profile.runtimeInit}({ engineFactory, engineWasmPath: ${JSON.stringify(engineWasmPath)}, sideModuleFactories, sceneNames: ${JSON.stringify(scenes.map((s) => s.name))}, firstScene: ${JSON.stringify(sceneName)}${opts.ySortLayers ? `, ySortLayers: ${opts.ySortLayers >>> 0}` : ''}${opts.colorSpace === 'linear' ? `, colorSpace: 'linear'` : ''}${opts.screenFit && opts.screenFit.scaleMode >= 0 ? `, screenFit: ${JSON.stringify(opts.screenFit)}` : ''} });\n` +
`}\n`;
progress({ phase: 'Bundling game' });
try {
diff --git a/desktop/tests/export-wechat.test.ts b/desktop/tests/export-wechat.test.ts
index f50b56c9a..6b0390e93 100644
--- a/desktop/tests/export-wechat.test.ts
+++ b/desktop/tests/export-wechat.test.ts
@@ -66,6 +66,7 @@ describe('exportGame (wechat)', () => {
platform: 'wechat',
wechatAppid: 'wxTEST0123456789',
orientation: 'landscape',
+ screenFit: { designWidth: 1280, designHeight: 720, scaleMode: 2, matchWidthOrHeight: 0.5 },
});
expect(res.ok).toBe(true);
@@ -92,6 +93,9 @@ describe('exportGame (wechat)', () => {
// The boot config names the staged glue's .wasm twin — WXWebAssembly
// instantiates by package-relative path, so the runtime must not guess.
expect(bundle).toContain('wasm/esengine.wasm');
+ // The project camera fit rides the boot config into initWeChatRuntime.
+ expect(bundle).toContain('screenFit');
+ expect(bundle).toMatch(/"scaleMode":\s*2/);
// Config + runtime copy.
const pcfg = JSON.parse(readFileSync(path.join(out, 'project.config.json'), 'utf8'));
diff --git a/sdk/src/wechatRuntime.ts b/sdk/src/wechatRuntime.ts
index 4273ecc6e..68833f454 100644
--- a/sdk/src/wechatRuntime.ts
+++ b/sdk/src/wechatRuntime.ts
@@ -78,6 +78,9 @@ export interface WeChatRuntimeConfig {
ySortLayers?: number;
/** Project color space — 'linear' boots the linear-light pipeline (Project Settings → Rendering). */
colorSpace?: 'gamma' | 'linear';
+ /** Project camera fit (Project Settings → Display) — letterboxes the design resolution
+ * without a UI Canvas; absent = no fit (raw orthoSize). */
+ screenFit?: { designWidth: number; designHeight: number; scaleMode: number; matchWidthOrHeight: number };
/** id → emscripten factory (`require('./wasm/<file>.js')`); the generated
* game.js supplies exactly the modules the scene needs. Physics + spine
* self-gate off these via {@link createWeChatSideModuleHost}. */
@@ -143,6 +146,7 @@ export async function initWeChatRuntime(config: WeChatRuntimeConfig): Promise<vo
glContextHandle: glHandle,
ySortLayers: config.ySortLayers,
colorSpace: config.colorSpace,
+ screenFit: config.screenFit,
getViewportSize: () => ({
width: canvas.width,
height: canvas.height,