feat: add mobile touch controls to Null Pow!#10
Closed
penta2himajin wants to merge 8 commits into
Closed
Conversation
Add swipe gesture detection for directional input (swipe left/right/up/down to change direction) and tap-to-start for game start/restart. Also adds an on-screen D-pad overlay on touch devices during gameplay as a fallback input method. Overlay text adapts to show touch-specific instructions on mobile. https://claude.ai/code/session_01Acnw2xmmT7syDmbKsjnZkH
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
solidion | e16fbaf | Commit Preview URL Branch Preview URL |
Mar 25 2026, 03:38 AM |
Phaser's scene-level pointer events may not fire until the scene is fully initialized, making taps on the initial screen unresponsive. Switch to native DOM touchstart/touchend events on the game container, which are available immediately regardless of Phaser's boot state. https://claude.ai/code/session_01Acnw2xmmT7syDmbKsjnZkH
The initial screen only accepted Space key via KeyboardInput, making it impossible to start the game on mobile or by clicking. Add a pointerdown handler on the Game component (matching Breakout/Aquarium/Floppy Heads pattern) so click or tap starts/restarts the game from any non-play phase. Update overlay text to mention click as an option on desktop. https://claude.ai/code/session_01Acnw2xmmT7syDmbKsjnZkH
- Add "click on canvas starts the game" test (desktop) - Add "tap on canvas starts the game" test (mobile) - Add "swipe changes player direction" test (mobile, uses TouchEvent dispatch) - Fix beforeEach: use focus() instead of click()/tap() to avoid accidentally starting the game via the new onPointerDown handler All 17 null-pow E2E tests pass (desktop + mobile). https://claude.ai/code/session_01Acnw2xmmT7syDmbKsjnZkH
Root cause: KeyboardInput used `scene.input.keyboard!` (non-null assertion).
On mobile devices where Phaser's keyboard plugin may be null, this crashes
and prevents the entire Game children tree from rendering — including the
onPointerDown handler that should allow taps to start the game.
Fix:
- Rename KeyboardInput → GameInput, combining keyboard + pointer input
- Guard `scene.input.keyboard` with null check (safe skip on mobile)
- Register `scene.input.on("pointerdown")` directly inside the component
(fires reliably on both desktop click and mobile tap)
- Remove separate onPointerDown prop from <Game> (now handled in GameInput)
- Add E2E tests: JS error detection, synthetic TouchEvent tap, debug counters
https://claude.ai/code/session_01Acnw2xmmT7syDmbKsjnZkH
Two fixes:
1. Arrow keys caused page scrolling on desktop — switch from Phaser's
keyboard plugin to document.addEventListener("keydown") with
preventDefault(), matching Floppy Heads' approach.
2. Mobile tap still unreliable — bypass Phaser's input system entirely
and register pointerdown + touchstart listeners directly on the
canvas DOM element via scene.game.canvas. This eliminates dependency
on Phaser's internal touch→pointer conversion pipeline.
Also simplifies touch input: swipe handler now registered on canvas
(not #game-container), tap handled by GameInput's canvas listeners.
https://claude.ai/code/session_01Acnw2xmmT7syDmbKsjnZkH
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implementation details
All changes are in
examples/null-pow/src/main.tsx:createSwipeHandler()— Tracks pointer down/up positions viaGame'sonPointerDown/onPointerUpprops, calculates swipe direction or detects tapsDPadcomponent — Phaser GameObjects (rectangles + text arrows) withinteractive+onPointerDownfor direct touch inputisTouchDevicedetection viaontouchstart/maxTouchPointsplayphase on touch devicesTest plan
https://claude.ai/code/session_01Acnw2xmmT7syDmbKsjnZkH