Overview
Camera functions enable viewport transformation for 2D and 3D rendering, as well as coordinate space conversions.2D Camera
Camera2D Type
The Camera2D class defines a 2D camera with offset, target, rotation, and zoom.Camera2D Properties
target
Gets or sets the camera target position in world space. Type:Vector2
rotation
Gets or sets the camera rotation in degrees. Type:Number
zoom
Gets or sets the camera zoom level. Type:Number (1.0 = normal, greater than 1.0 = zoomed in, less than 1.0 = zoomed out)
Camera2D Methods
beginMode2D
Initializes 2D mode with custom camera (must be called from Raylib class).endMode2D
Ends 2D mode (must be called from Raylib class).2D Coordinate Conversion
getWorldToScreen2D
Converts a 2D world position to screen space.World position
Camera to use for conversion
Vector2 - Screen position
getScreenToWorld2D
Converts a 2D screen position to world space.Screen position
Camera to use for conversion
Vector2 - World position
getCameraMatrix2D
Returns camera 2D transform matrix.Camera
Matrix - Camera transform matrix
3D Camera Functions
beginMode3D
Initializes 3D mode with custom camera.3D camera
endMode3D
Ends 3D mode.getWorldToScreen
Converts 3D world position to screen space.World position
Camera
Vector2 - Screen position
getScreenToWorldRay
Returns a ray from screen position into 3D world.Screen position
Camera
Ray - Ray from camera through screen point
getCameraMatrix
Returns camera 3D transform matrix.Camera
Matrix - Camera transform matrix
Camera Update (3D)
updateCamera
Updates camera position for selected mode.Camera to update (pointer)
Camera mode
updateCameraPro
Updates camera movement/rotation with pro parameters.Camera to update (pointer)
Movement vector
Rotation vector
Zoom value
Complete 2D Camera Example
Best Practices
The camera offset is typically set to the screen center (screenWidth/2, screenHeight/2) for smooth following behavior.