Skip to main content

Camera2D

Namespace: MonineEngine.Core

A 2D camera to modify how things are rendered on the screen.

public class Camera2D

Inheritance ObjectCamera2D

Properties

Position

Gets the position of the camera.

public Vector2 Position { get; private set; }

Property Value

Vector2

Rotation

Gets the rotation of the camera in degrees, with 0 being straight up.

public float Rotation { get; private set; }

Property Value

Single

Zoom

Gets the scale of the camera, acts as a zoom. Increase values to zoom out, decrease values to zoom in.

public Vector2 Zoom { get; private set; }

Property Value

Vector2

Origin

Gets the origin of the camera. Defaults to the center of the world.

public Vector2 Origin { get; private set; }

Property Value

Vector2

CenterPos

Gets the position at the center of the camera in world space.

public Vector2 CenterPos { get; }

Property Value

Vector2

Remarks:

For a screen space variant of this, use Engine.WindowCenter.

IsDirty

Gets if the camera is "dirty". If it is, the camera has changed view (position, rotation, zoom, or origin) since the last update.

public bool IsDirty { get; }

Property Value

Boolean

Constructors

Camera2D(Viewport)

Constructs a new Camera2D.

public Camera2D(Viewport viewport)

Parameters

viewport Viewport
The viewport of the game window.

Methods

CenterOrigin()

Places the origin of the Camera2D into the center of the camera.

public void CenterOrigin()

GetMatrix()

Retrieves the transform information of the camera as a .

public Matrix GetMatrix()

Returns

Matrix
A Matrix containing information for the position (offset by origin), rotation, and zoom of the camera.

SetPosition(Vector2)

Sets the position of the camera.

public void SetPosition(Vector2 pos)

Parameters

pos Vector2
The new position.

SetZoom(Vector2)

Sets the zoom of the camera.

public void SetZoom(Vector2 zoom)

Parameters

zoom Vector2
The new zoom.

SetRotation(Single)

Sets the rotation of the camera.

public void SetRotation(float rot)

Parameters

rot Single
The new rotation.

SetOrigin(Vector2)

Sets the origin of the camera.

public void SetOrigin(Vector2 pos)

Parameters

pos Vector2
The new origin.

ScreenToWorld(Vector2)

Takes a position on the screen and converts it to world space.

public Vector2 ScreenToWorld(Vector2 screenPos)

Parameters

screenPos Vector2
The position on the screen.

Returns

Vector2
The given position in world space.

WorldToScreen(Vector2)

Takes a position in the world and converts it to screen space.

public Vector2 WorldToScreen(Vector2 worldPos)

Parameters

worldPos Vector2
The position in the world.

Returns

Vector2
The given position in screen space.

GetBounds()

Gets the bounding box of the camera in world space.

public Rectangle GetBounds()

Returns

Rectangle
The bounding box of the camera as a .