UNPKG

multyx-client

Version:

Framework designed to simplify the creation of multiplayer browser games by addressing the complexities of managing server-client communication, shared state, and input handling

58 lines (57 loc) 2.26 kB
import { RawObject } from "./types"; export declare class Controller { private mouseGetter; listening: Set<string>; ws: WebSocket; preventDefault: boolean; keys: RawObject<boolean>; mouse: { x: number; y: number; down: boolean; centerX: number; centerY: number; scaleX: number; scaleY: number; }; constructor(ws: WebSocket); /** * Map the canvas to specified top left and bottom right positions * @param canvas HTML canvas element * @param canvasContext 2D rendering context for canvas * @param top Canvas position to correspond to top of canvas * @param left Canvas position to correspond to left of canvas * @param bottom Canvas position to correspond to bottom of canvas * @param right Canvas position to correspond to right of canvas * @param anchor Anchor the origin at a specific spot on the canvas */ mapCanvasPosition(canvas: HTMLCanvasElement, position: { top?: number; bottom?: number; left?: number; right?: number; anchor?: 'center' | 'left' | 'right' | 'top' | 'bottom' | 'topleft' | 'topright' | 'bottomleft' | 'bottomright'; }): void; /** * @param centerX Anchor x-value corresponding to mouse position x-value of 0 * @param centerY Anchor y-value corresponding to mouse position y-value of 0 * @param anchor HTML Element to read mouse position relative to * @param scaleX Number of anchor pixels corresponding to a mouse position x-value change of 1 * @param scaleY Number of anchor pixels corresponding to a mouse position y-value change of 1 */ mapMousePosition(centerX: number, centerY: number, anchor?: HTMLElement, scaleX?: number, scaleY?: number): void; /** * Map mouse position to the corresponding canvas coordinates on screen * @param canvas Canvas element in DOM */ mapMouseToCanvas(canvas: HTMLCanvasElement): void; /** * Utilize mouse coordinates of another object * @param mouseGetter Callback that returns the mouse coordinates at any given time */ setMouseAs(mouseGetter: () => { x: number; y: number; }): void; private relayInput; }