Component·phaserthree·v1.0.0·MIT
Mobile Joystick
On-screen virtual joystick for touch input. Renders to a DOM element; exposes a 2D vector for gameplay. Engine-agnostic.
#mobile#touch#joystick#input
Install
npx gamecn add mobile-joystickSource preview
Compatibility
| Engines | phaser >=3.80.0 <4.0.0three >=0.160.0 |
| Frameworks | vanilla, react |
| Languages | typescript |
| Bundlers | vite |
| Platforms | web, mobile-web |
Files installed
- {components}/MobileJoystick.ts
- docs/gamecn/mobile-joystick.md(docs)
Notes
Usage
import { MobileJoystick } from "@/components/MobileJoystick";
const stick = new MobileJoystick({
parent: document.getElementById("game")!,
radius: 60,
alwaysVisible: false,
});
// In your update loop:
function update(): void {
const { x, y } = stick.getVector(); // each in [-1, 1]
player.setVelocityX(x * speed);
player.setVelocityY(y * speed);
}
// Cleanup
stick.dispose();Behavior
- Hidden by default; reveals at the touch point on
pointerdown. - Tracks drag, clamped to
radius. - Snaps back on
pointerup. - Honors a
deadzone(default 10%) to suppress drift at rest.
Options
| Option | Default | Description |
|---|---|---|
parent |
required | Element receiving pointer events. |
radius |
60 |
Max drag distance in pixels. |
knobColor |
#ffffff |
Knob CSS color. |
ringColor |
rgba(255,255,255,0.25) |
Base ring color. |
alwaysVisible |
false |
Show even when idle. |
deadzone |
0.1 |
Magnitude below which the vector reports zero. |
Notes
- Sets
touch-action: noneon the parent so swipes don't scroll. Restored ondispose(). - Designed to coexist with desktop input — pair with the
input-manageritem for keyboard fallback.
Related
- Input ManagerUtility
Engine-agnostic input action mapper. Map logical actions ('jump', 'left') to keyboard bindings and query state without coupling gameplay code to the DOM keyboard API.
- Audio ManagerSystem
Web Audio-based SFX and music manager with named buses, volume control, and pluggable buffer loading. Engine-agnostic.
- Dialogue SystemSystem
Branching JSON-driven dialogue runner with choices and variables. Engine-agnostic — bring your own UI renderer.
- Save LoadUtility
Type-safe localStorage-backed save system with versioning and migrations. Engine-agnostic.