Methods
(static) canvasToWorld(canvasPoint, camera, canvasWidthopt, canvasHeightopt, pixelsPerUnitopt) → {Vector2}
Convert canvas internal pixel coordinates to world units based on a Camera.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
canvasPoint | Object | Coordinates in canvas pixels | ||
camera | object | Camera with position { x, y } and zoom number | ||
canvasWidth | number | <optional> | 1024 | Canvas pixel width (defaults to 1024 or camera/canvas dimensions) |
canvasHeight | number | <optional> | 768 | Canvas pixel height (defaults to 768 or camera/canvas dimensions) |
pixelsPerUnit | number | <optional> | 64 | Engine world unit conversion (64 px = 1 unit) |
- Source
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:
| Name | Type | Description |
|---|---|---|
screenPoint | Object | |
canvas | HTMLCanvasElement |
- Source
Returns:
- Type:
- Vector2
(static) screenToWorld(screenPoint, canvas, camera, pixelsPerUnitopt) → {Vector2}
Combined pipeline: convert screen client coordinates directly to world units.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
screenPoint | Object | |||
canvas | HTMLCanvasElement | |||
camera | object | |||
pixelsPerUnit | number | <optional> | 64 |
- Source
Returns:
- Type:
- Vector2
(static) worldToCanvas(worldPoint, camera, canvasWidthopt, canvasHeightopt, pixelsPerUnitopt) → {Vector2}
Convert world units back to canvas pixel coordinates.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
worldPoint | Object | |||
camera | object | |||
canvasWidth | number | <optional> | 1024 | |
canvasHeight | number | <optional> | 768 | |
pixelsPerUnit | number | <optional> | 64 |
- Source
Returns:
- Type:
- Vector2