Header menu logo Mibo

Camera2D Module

Helper functions for 2D Cameras (Orthographic projection).

Use these for top-down, side-scrolling, or any 2D game rendering.

Functions and values

Function or value Description

create position zoom viewportSize

Full Usage: create position zoom viewportSize

Parameters:
    position : Vector2 - Center of the camera in world units
    zoom : float32 - Scale factor (1.0 = pixel perfect, 2.0 = 2x zoom in)
    viewportSize : Point - The size of the screen/viewport in pixels

Returns: Camera

Creates a standard 2D Camera centered on the position.

position : Vector2

Center of the camera in world units

zoom : float32

Scale factor (1.0 = pixel perfect, 2.0 = 2x zoom in)

viewportSize : Point

The size of the screen/viewport in pixels

Returns: Camera
Example

 let camera = Camera2D.create playerPosition 1.0f (Point(800, 600))
val camera: obj

screenToWorld camera screenPos

Full Usage: screenToWorld camera screenPos

Parameters:
Returns: Vector2

Converts a screen position (pixels) to world position using the camera. Useful for mouse picking in 2D games.

camera : Camera
screenPos : Vector2
Returns: Vector2

viewportBounds camera viewport

Full Usage: viewportBounds camera viewport

Parameters:
Returns: Rectangle

Calculates the visible world bounds for the camera.

Useful for 2D culling (QuadTree queries, sprite visibility checks). Returns a Rectangle in world coordinates covering the visible area.

camera : Camera
viewport : Viewport
Returns: Rectangle

worldToScreen camera worldPos

Full Usage: worldToScreen camera worldPos

Parameters:
Returns: Vector2

Converts a world position to screen position (pixels).

camera : Camera
worldPos : Vector2
Returns: Vector2

Type something to start searching.