Skip to content

1681-engine / index / Pointer

Class: Pointer ​

Defined in: src/core/Pointer.ts:14

The mouse over the game canvas. Presses count only when they start on the canvas (not on the React UI above it); moves are followed everywhere so aiming keeps working at the edge of a panel.

Constructors ​

Constructor ​

ts
new Pointer(canvas): Pointer;

Defined in: src/core/Pointer.ts:32

Parameters ​

ParameterType
canvasHTMLCanvasElement

Returns ​

Pointer

Properties ​

worldX ​

ts
worldX: number = 0;

Defined in: src/core/Pointer.ts:24


worldY ​

ts
worldY: number = 0;

Defined in: src/core/Pointer.ts:25


x ​

ts
x: number = 0;

Defined in: src/core/Pointer.ts:22

Screen position relative to the canvas, in CSS pixels.


y ​

ts
y: number = 0;

Defined in: src/core/Pointer.ts:23


ignorePress ​

ts
static ignorePress: ((e) => boolean) | null = null;

Defined in: src/core/Pointer.ts:19

A press this returns true for is not counted as a held button (e.g. Shift + right-click opening a context menu instead of firing what the right button is bound to). Unset, every press counts.

Accessors ​

locked ​

Get Signature ​

ts
get locked(): boolean;

Defined in: src/core/Pointer.ts:78

True while the canvas holds the pointer (lock).

Returns ​

boolean

Methods ​

destroy() ​

ts
destroy(): void;

Defined in: src/core/Pointer.ts:107

Returns ​

void


leftButtonDown() ​

ts
leftButtonDown(): boolean;

Defined in: src/core/Pointer.ts:69

Returns ​

boolean


lock() ​

ts
lock(options?): Promise<boolean>;

Defined in: src/core/Pointer.ts:86

Locks the pointer to the canvas for mouse-look: the cursor hides and takeMovement returns how far the mouse went. Call from a press or key handler (browsers allow it only in a gesture); resolves whether the lock holds.

Parameters ​

ParameterType
options{ raw?: boolean; }
options.raw?boolean

Returns ​

Promise<boolean>


rightButtonDown() ​

ts
rightButtonDown(): boolean;

Defined in: src/core/Pointer.ts:73

Returns ​

boolean


takeMovement() ​

ts
takeMovement(): object;

Defined in: src/core/Pointer.ts:96

The mouse travel (CSS pixels) since the last call while locked, then zeroed; read it once per step.

Returns ​

object

x ​
ts
x: number;
y ​
ts
y: number;

unlock() ​

ts
unlock(): void;

Defined in: src/core/Pointer.ts:91

Returns ​

void


updateWorldPoint() ​

ts
updateWorldPoint(cam): void;

Defined in: src/core/Pointer.ts:102

Parameters ​

ParameterType
camCamera

Returns ​

void

Released under the MIT License.