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 camera struct's fields are immutable, so the movement helpers (smoothFollow / clampTarget) return a new camera rather than mutating in place.

Functions and values

Function or value Description

clampTarget camera minX minY maxX maxY

Full Usage: clampTarget camera minX minY maxX maxY

Parameters:
    camera : Camera2D
    minX : float32
    minY : float32
    maxX : float32
    maxY : float32

Returns: Camera2D
Modifiers: inline

Clamp the camera position to a world bounds rectangle, returning a new camera.

camera : Camera2D
minX : float32
minY : float32
maxX : float32
maxY : float32
Returns: Camera2D

create position zoom viewportSize

Full Usage: create position zoom viewportSize

Parameters:
    position : Vector2 - World position the camera follows.
    zoom : float32 - Zoom factor (1.0 = default).
    viewportSize : Vector2 - Size of the viewport in pixels (used to compute origin).

Returns: Camera2D
Modifiers: inline

Creates a Camera2D centered on the given position.

position : Vector2

World position the camera follows.

zoom : float32

Zoom factor (1.0 = default).

viewportSize : Vector2

Size of the viewport in pixels (used to compute origin).

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:
Returns: Vector2
Modifiers: inline

Converts a screen position (pixels) to world position.

camera : Camera2D
screenPos : Vector2
Returns: Vector2

smoothFollow camera target speed

Full Usage: smoothFollow camera target speed

Parameters:
Returns: Camera2D
Modifiers: inline

Smoothly interpolate the camera position toward a world position, returning a new camera.

camera : Camera2D
target : Vector2
speed : float32
Returns: Camera2D

splitScreenBottom camera clearColor bounds

Full Usage: splitScreenBottom camera clearColor bounds

Parameters:
    camera : Camera2D
    clearColor : Color
    bounds : Rectangle - Parent viewport bounds in pixels (typically the window size).

Returns: Camera2DConfig
Modifiers: inline

Split-screen bottom half. Clears with given color.

camera : Camera2D
clearColor : Color
bounds : Rectangle

Parent viewport bounds in pixels (typically the window size).

Returns: Camera2DConfig

splitScreenLeft camera clearColor bounds

Full Usage: splitScreenLeft camera clearColor bounds

Parameters:
    camera : Camera2D
    clearColor : Color
    bounds : Rectangle - Parent viewport bounds in pixels (typically the window size).

Returns: Camera2DConfig
Modifiers: inline

Split-screen left half. Clears with given color.

camera : Camera2D
clearColor : Color
bounds : Rectangle

Parent viewport bounds in pixels (typically the window size).

Returns: Camera2DConfig

splitScreenRight camera clearColor bounds

Full Usage: splitScreenRight camera clearColor bounds

Parameters:
    camera : Camera2D
    clearColor : Color
    bounds : Rectangle - Parent viewport bounds in pixels (typically the window size).

Returns: Camera2DConfig
Modifiers: inline

Split-screen right half. Clears with given color.

camera : Camera2D
clearColor : Color
bounds : Rectangle

Parent viewport bounds in pixels (typically the window size).

Returns: Camera2DConfig

splitScreenTop camera clearColor bounds

Full Usage: splitScreenTop camera clearColor bounds

Parameters:
    camera : Camera2D
    clearColor : Color
    bounds : Rectangle - Parent viewport bounds in pixels (typically the window size).

Returns: Camera2DConfig
Modifiers: inline

Split-screen top half. Clears with given color.

camera : Camera2D
clearColor : Color
bounds : Rectangle

Parent viewport bounds in pixels (typically the window size).

Returns: Camera2DConfig

toMatrix c

Full Usage: toMatrix c

Parameters:
Returns: Matrix
Modifiers: inline

Computes the SpriteBatch transform matrix for this camera.

The matrix applies: translate by -position, rotate, scale by zoom, then translate by origin. Pass this to SpriteBatch.Begin(transformMatrix=...).

c : Camera2D
Returns: Matrix

viewportBounds camera width height

Full Usage: viewportBounds camera width height

Parameters:
    camera : Camera2D
    width : float32
    height : float32

Returns: Rectangle
Modifiers: inline

Calculates the visible world bounds for a MonoGame Camera2D.

The result is a pixel Rectangle (MonoGame's Rectangle is int-based).

camera : Camera2D
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 pixel coordinates.

viewport : Rectangle
config : Camera2DConfig
Returns: Camera2DConfig

worldToScreen camera worldPos

Full Usage: worldToScreen camera worldPos

Parameters:
Returns: Vector2
Modifiers: inline

Converts a world position to screen position (pixels).

camera : Camera2D
worldPos : Vector2
Returns: Vector2

Type something to start searching.