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.

fix(minigame): a tap on vivo's quick game lands where the finger is

esenginec23a0f017eae
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3a06d28e0..89ad7ec5d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,6 +22,7 @@ published separately; it ships inside the editor.
### Fixed
+- A tap on vivo's quick game lands where the finger is: the host reports touches in physical pixels, and every tap landed off the screen.
- Games on vivo's quick game run past their first frame: the frame loop now hands requestAnimationFrame a handler the runtime accepts.
- The debug channel works on vivo's quick game: logs arrive in batches, and a replay is sent at the size the Frame Debugger shows instead of the whole screen.
- A native build loads a remote group's textures from the CDN — they never loaded before — and after a hot update, from its disk cache when offline.
diff --git a/sdk/src/platform/minigame/adapter.ts b/sdk/src/platform/minigame/adapter.ts
index 300afa106..e72f811ce 100644
--- a/sdk/src/platform/minigame/adapter.ts
+++ b/sdk/src/platform/minigame/adapter.ts
@@ -476,12 +476,16 @@ export class MiniGamePlatformAdapter implements PlatformAdapter {
}
const pointer = createPrimaryPointer(callbacks);
+ // A pointer is read in logical pixels and scaled by pixelRatio to reach the
+ // canvas; a host that reports touches in physical pixels would land every
+ // tap pixelRatio times too far out, past the edge of the screen.
+ const toLogical = this.profile_.windowInPhysicalPixels ? 1 / this.devicePixelRatio() : 1;
const onTouchStart = (res: MiniGameTouchEvent) => {
- for (const touch of res.changedTouches) pointer.start(touch.identifier, touch.clientX, touch.clientY);
+ for (const touch of res.changedTouches) pointer.start(touch.identifier, touch.clientX * toLogical, touch.clientY * toLogical);
};
const onTouchMove = (res: MiniGameTouchEvent) => {
- for (const touch of res.changedTouches) pointer.move(touch.identifier, touch.clientX, touch.clientY);
+ for (const touch of res.changedTouches) pointer.move(touch.identifier, touch.clientX * toLogical, touch.clientY * toLogical);
};
const onTouchEnd = (res: MiniGameTouchEvent) => {
for (const touch of res.changedTouches) pointer.end(touch.identifier);
diff --git a/sdk/src/platform/minigame/api.ts b/sdk/src/platform/minigame/api.ts
index cd4be58e7..43e481593 100644
--- a/sdk/src/platform/minigame/api.ts
+++ b/sdk/src/platform/minigame/api.ts
@@ -438,9 +438,10 @@ export interface MiniGameProfile {
request(request: PlatformPaymentRequest): Promise<void>;
};
- /** The host reports `windowWidth`/`windowHeight` in physical pixels rather
- * than WeChat's logical ones (vivo: 2340 wide beside a pixelRatio of 2.75), so
- * multiplying by pixelRatio again would size the screen past the GPU's limit. */
+ /** The host reports `windowWidth`/`windowHeight` and touch positions in physical
+ * pixels rather than WeChat's logical ones (vivo: 2340 wide beside a pixelRatio
+ * of 2.75), so multiplying by pixelRatio again would size the screen past the
+ * GPU's limit and put every tap off it. */
windowInPhysicalPixels?: boolean;
/** The recording length this vendor accepts, when its recorder's shape is
diff --git a/sdk/tests/quickgame-profile.test.ts b/sdk/tests/quickgame-profile.test.ts
index 91754c9b2..8f32e5d59 100644
--- a/sdk/tests/quickgame-profile.test.ts
+++ b/sdk/tests/quickgame-profile.test.ts
@@ -3,7 +3,7 @@
/**
* @file What the quick-game hosts needed that no other vendor did, each found
* by running a package on vivo's engine: a window measured in physical
- * pixels, WebAssembly behind a switch, and a WebGL2 context that offers
+ * pixels (touches too), WebAssembly behind a switch, and a WebGL2 context that offers
* an extension WebGL2 does not have.
*/
import { describe, it, expect, vi, afterEach } from 'vitest';
@@ -28,6 +28,25 @@ describe('the quick-game hosts', () => {
expect(screen({})).toMatchObject({ width: 6435, height: 2970 });
});
+ it('take a touch measured in physical pixels as the logical position every pointer reader scales', () => {
+ let touchStart: ((res: unknown) => void) | undefined;
+ const downs: number[][] = [];
+ const adapter = new MiniGamePlatformAdapter({
+ id: 'x', hostLabel: 'x', windowInPhysicalPixels: true,
+ global: {
+ getSystemInfoSync: () => ({ windowWidth: 2340, windowHeight: 1080, pixelRatio: 2.75 }),
+ onTouchStart: (cb: (res: unknown) => void) => { touchStart = cb; },
+ onTouchMove: () => {}, onTouchEnd: () => {},
+ } as unknown as MiniGameGlobal,
+ } as MiniGameProfile);
+ adapter.bindInputEvents({
+ onKeyDown: () => {}, onKeyUp: () => {}, onPointerMove: () => {}, onPointerUp: () => {}, onWheel: () => {},
+ onPointerDown: (_b, x, y) => downs.push([x, y]),
+ });
+ touchStart!({ touches: [], changedTouches: [{ identifier: 0, clientX: 2200, clientY: 990 }] });
+ expect(downs).toEqual([[800, 360]]);
+ });
+
it('turn WebAssembly on before the engine is instantiated', async () => {
const order: string[] = [];
(globalThis as { qg?: unknown }).qg = {
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index a0b698e69..362b482cb 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -1088,4 +1088,6 @@ export const NOTED = {
{ note: 'The debug channel works on vivo\'s quick game: logs arrive in batches, and a replay is sent at the size the Frame Debugger shows instead of the whole screen.' },
'fix(frame-debugger): a device\'s replay is asked for at the size the panel shows':
{ note: 'The debug channel works on vivo\'s quick game: logs arrive in batches, and a replay is sent at the size the Frame Debugger shows instead of the whole screen.' },
+ 'fix(minigame): a tap on vivo\'s quick game lands where the finger is':
+ { note: 'A tap on vivo\'s quick game lands where the finger is: the host reports touches in physical pixels, and every tap landed off the screen.' },
};