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): distinguish motion requests from sensor samples
yhhdf45ba23cd52
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 30d340f8f..93e975abb 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -20,7 +20,7 @@ published separately; it ships inside the editor.### Added-- **Mobile controls share InputMap and device capability results.** Fixed/follow virtual joysticks and held buttons support independent touches, mouse Play preview, radial dead zones and cancellation. Web, mini-game and native adapters expose motion, vibration and screen wake with explicit unavailable/denied results; browser fullscreen and pointer lock observe exits. The Mobile Controls example demonstrates the workflow. Physical device acceptance remains pending.+- **Mobile controls share InputMap and device capability results.** Fixed/follow virtual joysticks and held buttons support independent touches, mouse Play preview, radial dead zones and cancellation. Web, mini-game and native adapters expose motion, vibration and screen wake with explicit unavailable/denied results; browser fullscreen and pointer lock observe exits. The Mobile Controls example distinguishes request success from raw sensor data and clears tilt when channels disappear. Physical device acceptance remains pending.### Fixeddiff --git a/examples/mobile-controls/README.md b/examples/mobile-controls/README.mdindex f8d523aac..a0f47471d 100644--- a/examples/mobile-controls/README.md+++ b/examples/mobile-controls/README.md@@ -11,6 +11,9 @@ texture filtering and explicit world layers. See [asset licenses](ASSET_LICENSESThe top buttons request motion, screen wake, browser fullscreen and pointer lockfrom the player's own release event. The status text displays the request result.API availability is not proof that the current device has a sensor or motor.+The sensor-data indicator shows waiting, receiving, empty raw channels, or paused+separately from the request result. A successful request with empty channels does+not enable tilt movement; use a phone with motion sensors to verify real readings.- Web motion and screen wake require a secure context (HTTPS or localhost).- iOS Safari asks for motion permission; denial is a returned `denied` result.diff --git a/examples/mobile-controls/src/main.ts b/examples/mobile-controls/src/main.tsindex 17dc1576e..bc5c9abea 100644--- a/examples/mobile-controls/src/main.ts+++ b/examples/mobile-controls/src/main.ts@@ -9,6 +9,7 @@ const controls = new InputMap({ Move: Axis2D(Keys2D('KeyW', 'KeyS', 'KeyA', 'KeyFire: Button(Key('Space'), Virtual('fire')) });let tilt = { x: 0, y: 0 };let motion = false;+let motionData = 'off';let status: Entity | null = null;let message = 'Drag the left stick and hold Fire. WASD / Space also work.';let hits = 0;@@ -32,8 +33,9 @@ addStartupSystem(defineSystem([Res(UIEvents), GetWorld()], (events, world) => {world.insert(handle.entity, Name, { value: text });};button('Tilt controls', 30, () => {- if (motion) { motion = false; tilt = { x: 0, y: 0 }; void Device.motion.stop().then(report('Motion stopped')); return; }+ if (motion) { motion = false; motionData = 'off'; tilt = { x: 0, y: 0 }; void Device.motion.stop().then(report('Motion stopped')); return; }const caps = Device.capabilities();+ motionData = 'waiting';void Device.motion.start({ accelerometer: caps.accelerometer, gyroscope: caps.gyroscope }).then(result => {motion = result.status === 'ok'; report('Motion')(result);});@@ -42,10 +44,17 @@ addStartupSystem(defineSystem([Res(UIEvents), GetWorld()], (events, world) => {button('Fullscreen', 410, () => { void Device.fullscreen(!Device.state().fullscreen).then(report('Fullscreen')); });button('Pointer lock', 600, () => { void Device.pointerLock(!Device.state().pointerLocked).then(report('Pointer lock')); });Device.motion.onChange(sample => {- if (!motion || !sample.gravity) return;+ if (!motion) return;+ const hasRawMotion = !!(sample.acceleration || sample.accelerationIncludingGravity || sample.gyroscope);+ motionData = hasRawMotion ? 'receiving' : 'no raw channels';+ if (!hasRawMotion) { tilt = { x: 0, y: 0 }; return; }+ if (!sample.gravity) return;tilt = { x: Math.max(-1, Math.min(1, sample.gravity.x / 5)), y: Math.max(-1, Math.min(1, sample.gravity.y / 5)) };});- Device.onChange(state => { if (!state.motionActive) tilt = { x: 0, y: 0 }; });+ Device.onChange(state => {+ if (!state.motionActive) { tilt = { x: 0, y: 0 }; motionData = motion ? 'paused' : 'off'; }+ else motionData = 'waiting';+ });const hint = spawnUIEntity({ world, parent: canvas,node: { position: UIPositionType.Absolute, insetLeft: px(230), insetTop: px(390), width: px(355), height: px(40) },visual: { color: { r: 0.075, g: 0.09, b: 0.14, a: 0.95 } },@@ -86,7 +95,7 @@ addSystemToSchedule(Schedule.Update, defineSystem([Res(Input), Res(Time), GetWor}if (status !== null && world.valid(status)) {const caps = Device.capabilities();- const content = `${message}\nHits: ${hits} · Motion API: ${caps.accelerometer ? 'available' : 'unavailable'} · Vibration API: ${caps.vibration ? 'available' : 'unavailable'}`;+ const content = `${message}\nHits: ${hits} / Sensor data: ${motion ? motionData : 'off'} / Vibration API: ${caps.vibration ? 'available' : 'unavailable'}`;if (world.get(status, Text).content !== content) world.insert(status, Text, { ...world.get(status, Text), content });}}, { name: 'MobileControlsUpdate' }));diff --git a/examples/mobile-controls/thumbnail.png b/examples/mobile-controls/thumbnail.pngindex 4865771c3..0ee7f1b23 100644Binary files a/examples/mobile-controls/thumbnail.png and b/examples/mobile-controls/thumbnail.png differdiff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex 80cd282e7..c615a3b27 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -28,6 +28,8 @@ export const NOTES_FLOOR = 'v0.65.0';* the reader recognises anyway.*/export const NOTED = {+ 'fix(examples): distinguish motion requests from sensor samples':+ { note: 'Mobile controls share InputMap and device capability results.' },'feat(examples): refresh sprite rendering with CC0 space art':{ note: 'Sprite rendering has a complete space art example.' },'perf(renderer): coalesce sorted 2d batch index gaps':