Skip to main content

Function: screenToWorldSpace()

screenToWorldSpace(screenPosition, cameraPosition, cameraZoom, screenWidth, screenHeight): Vector2

Defined in: rendering/transforms/screen-to-world-space.ts:18

Converts a position from screen space to world space.

Forge uses a Y-up world coordinate system (positive Y points upward), while the canvas uses a Y-down screen coordinate system (positive Y points downward). The rendering projection matrix applies a negative Y scale (-2 / height) to account for this, so this function must flip Y when converting screen → world.

Parameters

screenPosition

Vector2

The position in screen space (e.g., mouse position relative to the viewport).

cameraPosition

Vector2

The position of the camera in world space.

cameraZoom

number

The zoom level of the camera.

screenWidth

number

The width of the screen in pixels.

screenHeight

number

The height of the screen in pixels.

Returns

Vector2

The position in world space.