InputCoordinates

Robust coordinate conversion utilities across screen pixels, high-DPI canvas pixels, viewport cameras, and world-space units.

Constructor

new InputCoordinates()

Methods

(static) canvasToWorld(canvasPoint, camera, canvasWidthopt, canvasHeightopt, pixelsPerUnitopt) → {Vector2}

Convert canvas internal pixel coordinates to world units based on a Camera.

Parameters:
NameTypeAttributesDefaultDescription
canvasPointObject

Coordinates in canvas pixels

cameraobject

Camera with position { x, y } and zoom number

canvasWidthnumber<optional>
1024

Canvas pixel width (defaults to 1024 or camera/canvas dimensions)

canvasHeightnumber<optional>
768

Canvas pixel height (defaults to 768 or camera/canvas dimensions)

pixelsPerUnitnumber<optional>
64

Engine world unit conversion (64 px = 1 unit)

Returns:
Type: 
Vector2

(static) screenToCanvas(screenPoint, canvas) → {Vector2}

Convert screen client coordinates (e.g. from mouse or touch event) into canvas internal pixels. Accurately corrects for CSS letterboxing, scaling, and high-DPI ratios.

Parameters:
NameTypeDescription
screenPointObject
canvasHTMLCanvasElement
Returns:
Type: 
Vector2

(static) screenToWorld(screenPoint, canvas, camera, pixelsPerUnitopt) → {Vector2}

Combined pipeline: convert screen client coordinates directly to world units.

Parameters:
NameTypeAttributesDefaultDescription
screenPointObject
canvasHTMLCanvasElement
cameraobject
pixelsPerUnitnumber<optional>
64
Returns:
Type: 
Vector2

(static) worldToCanvas(worldPoint, camera, canvasWidthopt, canvasHeightopt, pixelsPerUnitopt) → {Vector2}

Convert world units back to canvas pixel coordinates.

Parameters:
NameTypeAttributesDefaultDescription
worldPointObject
cameraobject
canvasWidthnumber<optional>
1024
canvasHeightnumber<optional>
768
pixelsPerUnitnumber<optional>
64
Returns:
Type: 
Vector2