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.

The raylib Camera2D is a native mutable struct. The read-only helpers (viewportBounds/screenToWorld/worldToScreen) take it by inref (no copy, use &camera at the call site), the movement helpers (smoothFollow/clampTarget) take it by byref and mutate it in place, and the config builders take it by value (the camera is stored in the config regardless).

Functions and values

Function or value Description

clampTarget camera minX minY maxX maxY

Full Usage: clampTarget camera minX minY maxX maxY

Parameters:
    camera : byref<Camera2D> - Passed by reference (&camera) so mutations are visible to the caller.
    minX : float32
    minY : float32
    maxX : float32
    maxY : float32

Modifiers: inline

Clamp the camera target to a world bounds rectangle.

camera : byref<Camera2D>

Passed by reference (&camera) so mutations are visible to the caller.

minX : float32
minY : float32
maxX : float32
maxY : float32

create position zoom viewportSize

Full Usage: create position zoom viewportSize

Parameters:
Returns: Camera2D
Modifiers: inline

Creates a raylib Camera2D centered on the given position.

position : Vector2
zoom : float32
viewportSize : Vector2
Returns: Camera2D

render camera

Full Usage: render camera

Parameters:
Returns: Camera2DConfig
Modifiers: inline

Create a rendering config from a 2D camera. Defaults: fullscreen, no clear.

camera : Camera2D
Returns: Camera2DConfig

screenToWorld camera screenPos

Full Usage: screenToWorld camera screenPos

Parameters:
    camera : inref<Camera2D> - Passed by read-only reference (&camera) to avoid copying the native struct.
    screenPos : Vector2

Returns: Vector2
Modifiers: inline

Converts a screen position (pixels) to world position.

camera : inref<Camera2D>

Passed by read-only reference (&camera) to avoid copying the native struct.

screenPos : Vector2
Returns: Vector2

smoothFollow camera target speed

Full Usage: smoothFollow camera target speed

Parameters:
    camera : byref<Camera2D> - Passed by reference (&camera) so mutations are visible to the caller.
    target : Vector2
    speed : float32

Modifiers: inline

Smoothly interpolate the camera target toward a world position.

camera : byref<Camera2D>

Passed by reference (&camera) so mutations are visible to the caller.

target : Vector2
speed : float32

splitScreenBottom camera clearColor

Full Usage: splitScreenBottom camera clearColor

Parameters:
Returns: Camera2DConfig
Modifiers: inline

Split-screen bottom half. Clears with given color.

camera : Camera2D
clearColor : Color
Returns: Camera2DConfig

splitScreenLeft camera clearColor

Full Usage: splitScreenLeft camera clearColor

Parameters:
Returns: Camera2DConfig
Modifiers: inline

Split-screen left half. Clears with given color.

camera : Camera2D
clearColor : Color
Returns: Camera2DConfig

splitScreenRight camera clearColor

Full Usage: splitScreenRight camera clearColor

Parameters:
Returns: Camera2DConfig
Modifiers: inline

Split-screen right half. Clears with given color.

camera : Camera2D
clearColor : Color
Returns: Camera2DConfig

splitScreenTop camera clearColor

Full Usage: splitScreenTop camera clearColor

Parameters:
Returns: Camera2DConfig
Modifiers: inline

Split-screen top half. Clears with given color.

camera : Camera2D
clearColor : Color
Returns: Camera2DConfig

viewportBounds camera width height

Full Usage: viewportBounds camera width height

Parameters:
    camera : inref<Camera2D> - Passed by read-only reference (&camera) to avoid copying the native struct.
    width : float32
    height : float32

Returns: Rectangle
Modifiers: inline

Calculates the visible world bounds for a raylib Camera2D.

camera : inref<Camera2D>

Passed by read-only reference (&camera) to avoid copying the native struct.

width : float32
height : float32
Returns: Rectangle

withClear color config

Full Usage: withClear color config

Parameters:
Returns: Camera2DConfig
Modifiers: inline

Clear with this color before rendering.

color : Color
config : Camera2DConfig
Returns: Camera2DConfig

withViewport viewport config

Full Usage: withViewport viewport config

Parameters:
Returns: Camera2DConfig
Modifiers: inline

Set viewport in normalized screen coordinates (0-1).

viewport : Rectangle
config : Camera2DConfig
Returns: Camera2DConfig

worldToScreen camera worldPos

Full Usage: worldToScreen camera worldPos

Parameters:
    camera : inref<Camera2D> - Passed by read-only reference (&camera) to avoid copying the native struct.
    worldPos : Vector2

Returns: Vector2
Modifiers: inline

Converts a world position to screen position (pixels).

camera : inref<Camera2D>

Passed by read-only reference (&camera) to avoid copying the native struct.

worldPos : Vector2
Returns: Vector2

Type something to start searching.