VirtualJoystick
On-screen analog joystick for touch devices. Returns normalized x/y values in [-1, 1] range.
VirtualJoystick
On-screen analog joystick for touch devices. Returns normalized x/y values in [-1, 1] range.
Examples
const joystick = new VirtualJoystick();
function loop() {
player.move(joystick.x, joystick.y);
requestAnimationFrame(loop);
}Members
x
x: numberHorizontal axis: -1 (left) to 1 (right), 0 when idle
y
y: numberVertical axis: -1 (up) to 1 (down), 0 when idle
angle
angle: number | nullAngle in radians (0 = right, PI/2 = down), or null when idle
magnitude
magnitude: numberDistance from center, 0 to 1
show
show(): voidMakes the joystick visible regardless of device detection.
hide
hide(): voidHides the joystick overlay.
destroy
destroy(): voidRemoves DOM listeners and tears down the joystick.