Underground 2 Revived
Play Need for Speed: Underground 2 (2004) in Chrome and Firefox with WebGPU graphics, Web Audio, up to 120 fps widescreen, controller support, free roam and Online races with friends. Fan project, not
翻譯準備中
個人 GitHub 帳號下公開儲存庫的擁有者可以登入並驗證所有權,自行管理介紹,無需管理員核准。
登入並產生驗證檔案,在 30 分鐘內將其提交至此儲存庫的預設分支。其他分支或分叉儲存庫中的檔案無效。然後在下方檢查檔案,即可無需管理員核准直接管理專案。請保留檔案以維持管理權限。
如需登入,將前往登入頁面。登入後請回到此處,再次點擊所選的驗證按鈕。
在專案資料夾中執行 /nomorevibe verify,即可驗證所有權並自行管理介紹。
一分鐘完成驗證Virtual on-screen joystick for React games: pointer and touch, deadzone, normalized vector output
翻譯準備中
取自儲存庫 README
正在載入完整 README。
檢視完整 README ↗A touch-anywhere floating virtual joystick for React canvas games. Press anywhere on the game viewport and the joystick appears under your thumb; drag to steer; lift to stop. It never takes over taps meant for buttons, links or form controls, and it claims exactly one pointer so a second finger can fire, jump or open a menu.
The package owns the parts that are easy to get subtly wrong: pointer claiming, host hit-testing, interactive-control exclusion, and the deadzone/clamp curve. Your game still owns what the vector means and how the joystick looks.
FloatingJoystick: the React component. Renders nothing until a touch begins, then a ring and
knob at the touch origin.normalizeJoystick: the pure deadzone, clamp and normalize function, usable without React or a
DOM.useKeyboardVectorMap: an opt-in WASD and arrow-key co-map that emits the same { x, y } shape,
for desktop testing and keyboard parity.claimArea and claimWidthFraction: say which presses the stick claims (the left 40% of the
screen, say), so the rest is free for look, drag or taps.pointerOwnership, createPointerOwnership and usePointerOwnership: a small pointer registry
that arbitrates which subsystem owns a finger, so a drag that starts on a station is not also a
stick or a look. The joystick claims through it.pnpm add input-joystick react react-dom
# or: npm install input-joystick react react-dom
React 18 or later is a peer dependency. The package ships ESM and CommonJS builds with types, has
no runtime dependencies and is marked sideEffects: false.
import { FloatingJoystick, useKeyboardVectorMap, type JoystickVector } from "input-joystick";
import { useRef } from "react";
export function Controls() {
const move = useRef({ x: 0, y: 0 });
const onJoystick = (vector: JoystickVector) => {
move.current = { x: vector.x, y: vector.y };
};
// Optional: keyboard parity on desktop.
useKeyboardVectorMap({ onChange: ({ x, y }) => (move.current = { x, y }) });
return <FloatingJoystick onChange={onJoystick} accent="#38bdf8" />;
}
Read move.current from your game loop. onChange fires on every pointer move while a touch is
held and once with a zero vector when it ends, so the loop never needs to track pointer lifetimes.
Mount FloatingJoystick inside the element that should accept the touch. By default its host is
the closest ancestor matching [data-testid="game-viewport"], falling back to its parent element;
pass hostSelector to scope it to your own viewport.
Claim only part of the host for the stick, and let other subsystems take the pointers they use:
import {
FloatingJoystick,
claimWidthFraction,
usePointerOwnership,
type JoystickVector,
} from "input-joystick";
function Controls({ onMove }: { onMove: (v: JoystickVector) => void }) {
const pointers = usePointerOwnership("look");
return (
<>
<FloatingJoystick claimArea={claimWidthFraction("left", 0.4)} onChange={onMove} />
<div
onPointerDown={(e) => pointers.claim(e.pointerId) && startLookDrag(e)}
onPointerUp={(e) => pointers.release(e.pointerId)}
/>
</>
);
}
A pointer the stick holds is refused to pointers.claim, and a pointer a station has claimed is never
taken by the stick. Claims are released when the pointer ends, is cancelled or the window loses
focus.
| Export | Kind | What it does |
|---|---|---|
FloatingJoystick | component | Claims one pointer inside its host, emits normalized vectors, draws the ring and knob. |
FloatingJoystickProps | type | onChange, disabled, label, radius, deadZone, accent, allowMouse, hostSelector, claimArea, ownership, owner. |
claimWidthFraction(side, fraction) | function | A ClaimArea for the fraction of the host's width from the "left" or "right" edge. |
ClaimArea, ClaimRect | types | (event, rect) => boolean over the pointerdown and the host's rectangle. |
pointerOwnership | value | The shared PointerOwnership registry the joystick uses by default. |
createPointerOwnership() | function | Makes an isolated PointerOwnership: claim, release, releaseAll, ownerOf, clear, onRelease, attach. |
usePointerOwnership(owner, options?) | hook | The registry bound to one owner, attached while mounted and released on unmount. |
PointerOwnership, PointerOwnershipTarget, PointerReleaseListener, OwnedPointers, UsePointerOwnershipOptions | types | The registry, its attach target and listener, the hook's result and options. |
normalizeJoystick(raw, radius, deadZone) | function | Pure deadzone, clamp and normalize math returning a JoystickVector. |
JoystickVector, RawOffset | types | { x, y, magnitude, angle } and { x, y }. |
Full signatures, defaults and behavior are in docs/API.md; the reasoning behind the design is in docs/ARCHITECTURE.md.
allowMouse to accept a mouse for desktop testing.button, a, input, textarea, select, summary, [role="button"] or anything
marked data-joystick-ignore never start the joystick.disabled releases any held pointer, reports a zero vector and ignores new touches.claimArea that rejects a press leaves it alone: nothing is claimed or prevented.| Supported | |
|---|---|
| React and React DOM | 18 or later (tested on 19.2) |
| Node.js (building and SSR import) | 22, 24 and 26 (maintained lines; engines >=22) |
| Browsers | Any with Pointer Events: current Chrome, Safari and Firefox on desktop and mobile |
| Module formats | ESM and CommonJS, each with matching type declarations |
The FloatingJoystick tests run in real Chromium because pointer capture and multi-touch
pointerId claiming cannot be driven faithfully by jsdom.
corepack enable
pnpm install --frozen-lockfile
pnpm exec playwright install chromium
pnpm verify # Biome, markdownlint, tsc, jsdom and Chromium tests at 100% coverage, build, publint, attw, packed-consumer smoke
See CONTRIBUTING.md and AGENTS.md.
useKeyboardVectorMap(options) |
| hook |
Maps keys to unit vectors and calls onChange({ x, y }). |
KeyboardVector, KeyboardVectorMapOptions | types | The hook's vector and options. |