Input · class
TouchControls
A reusable mobile scheme: dynamic stick on the first zone; look plus a primary tap/hold and secondary downward swipe on the second. The class reports generic control state. A game decides whether those signals mean jump, fire, crouch, slide, or anything else.
Explained in Moving things.
class TouchControlsimport { TouchControls } from '@driftengine/core';Constructor
new
constructor(input: InputSource, options?: TouchControlsOptions)Take the input surface, and optionally the two nodes the stick is drawn with.
| Parameter | Type | Description |
|---|---|---|
input | InputSource | |
options? | TouchControlsOptions |
More
Two forms, and the older one is kept working rather than deprecated. It was
(input, stickBase, stickNub, options), which put an output channel where a reader expects a
dependency — a consumer forbidden the page read the signature, concluded the class could not be
used without two HTMLElements, and built two it threw away. The options form says what is
true: the elements are how the stick is drawn, and drawing it is optional.
new TouchControls(input) is a working control scheme with no visible stick.
new
constructor(input: InputSource, stickBase: HTMLElement, stickNub: HTMLElement, options?: TouchControlsOptions)| Parameter | Type | Description |
|---|---|---|
input | InputSource | |
stickBase | HTMLElement | |
stickNub | HTMLElement | |
options? | TouchControlsOptions |
Properties
| Name | Type | Description |
|---|---|---|
moveX | number | |
moveY | number | |
primaryHeld | boolean | |
secondaryHeld | boolean | |
onFirstTouch | (() => void) | null |
Methods
tick
tick(nowMs: number): voidResolve a still second-zone touch into the generic primary hold.
| Parameter | Type | Description |
|---|---|---|
nowMs | number |
consumePrimaryPress
consumePrimaryPress(): booleanConsume the primary edge exactly once.
consumeLook
consumeLook(out: { dx: number; dy: number; }): voidDrain accumulated second-zone look motion into a caller-owned object.
| Parameter | Type | Description |
|---|---|---|
out | { dx: number; dy: number; } |
dispose
dispose(): void