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.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix(examples): the torch follows a pointer that MOVED, not one that reports (0,0)
esengine21b81dcaf4d5
diff --git a/examples/lighting-2d/src/systems/torch.ts b/examples/lighting-2d/src/systems/torch.tsindex 79569e7f2..d12b427d6 100644--- a/examples/lighting-2d/src/systems/torch.ts+++ b/examples/lighting-2d/src/systems/torch.ts@@ -8,16 +8,30 @@ import { Torch } from '../components';// world-space mouse position. UICameraInfo already projects the cursor through// the active camera, so no manual screen→world math is needed.//-// Until the pointer has actually moved, leave the torch where the scene put it.-// A cursor that has never been over the canvas reads as (0, 0) — the top-left-// corner — and following that puts the room's only light off in a corner, so the-// demo opens on a black screen and stays there for anyone who has not yet moved-// the mouse (and for every screenshot taken of it).+// Until the pointer has actually MOVED, leave the torch where the scene put it.+// A pointer that has never been used still reports a position — (0, 0) on the+// web, whatever the last touch left behind on a phone — and following it puts+// the room's only light in a corner, so the demo opens on a black screen for+// anyone who has not yet moved the mouse, and for every screenshot taken of it.+// Movement is the signal, not any particular resting value: a device with no+// mouse at all never produces one, which is the correct answer there.+let originX: number | null = null;+let originY: number | null = null;+let moved = false;+export const torchSystem = defineSystem([Query(Mut(Transform), Torch), Res(UICameraInfo), Res(Input)],(torches, camera: UICameraData, input: InputState) => {if (!camera.valid) return;- if (input.mouseX === 0 && input.mouseY === 0) return;+ if (!moved) {+ if (originX === null) {+ originX = input.mouseX;+ originY = input.mouseY;+ return;+ }+ if (input.mouseX === originX && input.mouseY === originY) return;+ moved = true;+ }for (const [, transform] of torches) {transform.position.x = camera.worldMouseX;transform.position.y = camera.worldMouseY;