Skip to content

PointerLock beta ​

Class of @v12-engine/client

ts
export declare class PointerLock

The pointer kept in the game (client.pointerLock): when (keep, the setting keepPointer), whether it is now (locked), kept and let go of in code (lock, release), where it is (at), and the element it is drawn with (cursor). The pause menu gives it back while it is open; losing it otherwise (Esc, which is the browser's, or another window) opens the pause menu. See the top of this file for how the game hears it

Members ​

constructor ​

ts
constructor(client: LockHost);

Constructs a new instance of the PointerLock class

at ​

ts
at(): {
        x: number;
        y: number;
    };

Where the pointer is, in the page's pixels (clientX, clientY): the client's own while it is kept

cursor ​

ts
readonly cursor: HTMLElement;

What the pointer is drawn with while it is kept: an element at the end of the game's, holding an image. A game draws its own by hiding it (display: none in its stylesheet, on [data-vg-pointer]) and putting its own at at()

dispose ​

ts
dispose(): void;

Lets go of the kept pointer, its listeners and its drawn cursor

keep ​

ts
get keep(): KeepPointer;

set keep(mode: KeepPointer);

When the pointer is kept: the setting keepPointer sets it. Never, as it starts

lock ​

ts
lock(): Promise<boolean>;

Asks the browser to keep the pointer in the game. It grants it only just after the player pressed something (a click, a key that is not Esc), and not again for a moment after it was let go of with Esc: true once it is kept

locked ​

ts
readonly locked: Accessor<boolean>;

Whether the pointer is kept in the game now. A signal

onChange ​

ts
onChange(listener: (locked: boolean, lost: boolean) => void): () => void;

Told each time the pointer is kept or given back: lost when it was not the client's doing (Esc, another window), which opens the pause menu. Gives back what stops it

refresh ​

ts
refresh(): void;

Draws the kept pointer with the image the CSS cursor of what is under it has (the game's cursors, the map's as the next click would do): the client does each frame, as that changes with what the pointer is over without it moving

release ​

ts
release(): void;

Gives the pointer back to the page: the pause menu does, and code may. Not lost: the menu does not open for it

wanted ​

ts
get wanted(): boolean;

Whether the pointer is to be kept now: as keep says, while the game is played and its menu is shut