2D camera for managing the view into the game world
The Camera class provides basic 2D view management including position,
bounds checking, and smooth movement. It integrates with the effects
system for advanced camera behaviors.
Example
camera = Camera.new
camera.set_bounds(0, 0, 2048, 1536) # Large scrollable area
camera.position = Vector2.new(512, 384) # Look at specific position
Constructors
new(x : Float32, y : Float32)
SourceInstance methods
apply_offset(world_x : Float32, world_y : Float32) : RL::Vector2
Apply camera offset (utility for manual calculations)
Sourcecenter_on(x : Float32, y : Float32, viewport_width : Int32 = Display.reference_width, viewport_height : Int32 = Display.reference_height)
Center camera on a world position
Sourcecenter_on(position : RL::Vector2)
Center camera on position vector
Sourcemin_x
Camera bounds (to keep camera within scene limits)
Sourcemin_x=(min_x : Float32)
Camera bounds (to keep camera within scene limits)
Sourcemove_to(x : Float32, y : Float32)
Move camera to position (instant or smooth based on settings)
Sourcemove_to(target : RL::Vector2)
Move camera to position vector
Sourceposition
Camera position in world coordinates
Sourceposition=(position : RL::Vector2)
Camera position in world coordinates
Sourcescreen_to_world(screen_x : Int32, screen_y : Int32) : RL::Vector2
Convert screen coordinates to world coordinates
Sourceset_bounds(scene_width : Int32, scene_height : Int32, viewport_width : Int32 = Display.reference_width, viewport_height : Int32 = Display.reference_height)
Set camera bounds based on scene size
Sourceset_bounds(min_x : Float32, min_y : Float32, max_x : Float32, max_y : Float32)
Set camera bounds explicitly
Sourceset_scene_size(scene_width : Int32, scene_height : Int32)
Convenience method for setting scene size (calls set_bounds)
Sourceshake(intensity : Float32, duration : Float32)
Shake the camera (trigger effect through effect system)
This is a convenience method that should integrate with effects
Sourcesmooth_enabled
Smooth movement properties
Sourcesmooth_enabled=(smooth_enabled : Bool)
Smooth movement properties
Sourcesmooth_speed=(smooth_speed : Float32)
Sourceupdate(dt : Float32)
Update camera (for smooth movement)
Sourcevisible?(world_x : Float32, world_y : Float32, margin : Float32 = 0.0_f32, viewport_width : Int32 = Display.reference_width, viewport_height : Int32 = Display.reference_height) : Bool
Check if a world position is visible
Sourcevisible?(rect : RL::Rectangle, margin : Float32 = 0.0_f32) : Bool
Check if a rectangle is visible
Sourcevisible_area(viewport_width : Int32 = Display.reference_width, viewport_height : Int32 = Display.reference_height) : RL::Rectangle
Get the visible area in world coordinates
Sourceworld_to_screen(world_x : Float32, world_y : Float32) : RL::Vector2
Convert world coordinates to screen coordinates
Source