-
Notifications
You must be signed in to change notification settings - Fork 0
Camera Manager
The Camera System controls how the game camera behaves in both Editor Mode (EDIT) and Play Mode (PLAY) using a single Camera2D node.
It supports:
- Free camera movement in editor mode (WASD + edge scrolling + panning)
- Smooth player-follow camera in play mode
- Zoom in/out using mouse wheel or + and - key
- Level boundary clamping based on world size
- State switching through a global game state system
This system replaces multiple camera controllers with a single unified state-based camera.
-
WASDor arrow keys → Move camera - Mouse at screen edges → Move camera
- Mouse wheel or + and - keys → Zoom in/out
- Middle mouse button and dragging moves
- Camera follows player automatically
- No manual input
- Edge scrolling camera movement
- Zoom system with limits
- tilemap boundary clamp
- Automatic tilemap-centering on start
Name the most important variables, their type, and what their purpose is
-
roamCellCount: float= An exported variable that determines how far a user can pan away from the level scene before being clamped. -
moveSpeed: float= An exported variable that determines how fast a user can move around the level scene when using WASD. -
edgeScrollSpeed: float= An exported variable that determines how fast a user can edge scroll. -
edgeScrollMargin: float= An exported variable that determines how far the mouse must be from the edge for the user to edge scroll. -
isPanning: bool= Whether the user is in the middle of panning the camera. -
panSpeed: float= How fast the user can pan the screen via middle mouse button click. -
zoomSpeed: float= An exported variable that determines how fast a user can zoom in or out the camera. -
maxZoomOut: float= An exported variable that determines how far a user can zoom out. -
maxZoomIn: float= An exported variable that determines how close a user can zoom in. -
playZoom: float= An exported variable that determines how zoomed a camera is on the player. -
tileSet: TileMapLayer= An exported variable for the main tile map. -
levelBounds: Rect2= The absolute level bounds so that the camera cannot zoom out too much. -
roamBounds: float= The absolute roam bounds so that the camera cannot drag too far out. -
playerReference: CharacterBody2D= The retrieved reference to the player. -
maxPlayerSearchAttempts: int= The max amount of times the player will be searched for.
Name of the most important functions, their parameters, and what they do.
-
func reset_camera() -> void: Resets the camera, and the player reference so that it has to be searched for again. -
func refresh_bounds() -> void: Adjusts camera bounds to current grid size. -
func try_find_player(delta: float) -> void: Searches for the first node in the "Player" group, which will be our player reference. Will only search up to maxPlayerSearchAttempts. -
func _input() -> void: Handles middle mouse button inputs, and camera "sprinting" (panning faster while holding shift). -
func process_build_camera(delta: float) -> void: Processes editor camera movement based on delta time. -
func process_edge_scrolling(delta: time) -> void: Processes edge scrolling movement with the editor camera based on delta time. -
func process_zoom(zoomAmount: float) -> void: Processes zooming based on the mouse position, and zooms in or out by the zoomAmount. -
func process_zoom_input() -> void: Processes the zoom input, and calls the process_zoom function based on the input given by the user. -
func process_player_camera() -> void: Follows the player, so long as there is a reference to it. -
func get_camera_bounds() -> Rect2: Converts the roam cell count to workable pixels, and returns it to the roamBounds. -
func clamp_camera_to_level() -> void: Prevents the camera from leaving the level outside of the roam/level bounds.
List and description of upcoming work/risks.
Future Work:
- Adding setting toggles for certain camera movements, such as edge pan.
Risks:
- No known risks.
- System is single-node for simplicity
- State switching is handled externally by
MasterManager - Camera assumes a rectangular tilemap level world
- Code follows modular function separation for readability
Resources
Known Issues
Future Work
Globals
Managers
- Main Menu Manager
- Master Manager
- Camera Manager
- Hotkey Manager
- Import Export Manager
- Audio Manager
- Animation Manager
- PopUp Manager
UI
Managers
- Editor Manager
- Tile Manager
- Entity Manager
- Icon Manager
- Preview Manager
- Tool Manager
- Asset Manager
- Custom Cursor Manager
Tiles & Entities
- Grid Lines
- Preview Line
- Tiles & Entities
- Enemies
- Patrolling Enemy
- Flying Enemy
- Shooting Enemy
- Stationary Enemy
- Moving Platform
- Property Editing
Asset Swapping
UI
Managers
Player