Skip to main content

Function: calculateVisibleWorldSize()

calculateVisibleWorldSize(canvasWidth, canvasHeight, verticalWorldUnits): Vector2

Defined in: rendering/utilities/calculate-visible-world-size.ts:16

Computes the full width/height, in world units, a camera's view spans at the given destination dimensions: verticalWorldUnits tall, with the width following automatically from the destination's aspect ratio. Use this instead of reading RenderContext.width/height in pixels directly for world-space layout (spawn bounds, movement limits, background sizing, ...), so that layout stays correct across resolutions and aspect ratios.

Parameters​

canvasWidth​

number

The render destination's width, in pixels.

canvasHeight​

number

The render destination's height, in pixels.

verticalWorldUnits​

number

The total world-space height the camera shows (see CameraEcsComponent.verticalWorldUnits).

Returns​

Vector2

The visible width/height, in world units.

Throws​

An error if any argument is not positive.