-
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 + 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 -
Scroll wheel or
+and-: Zoom in and out - Middle Mouse Button: Move Camera
- Camera will follow the player's position automatically.
- Settings to adjust deadzone, follow speed, zoom level, and if it clamps to the level's bounds.
- Minimum Zoom depends on the level size, allowing it to fully display levels regardless of how big they are.
- Scrolling in the editor state has a limit of 4 cells beyond the edge of the level.
Name the most important variables, their type, and what their purpose is
-
roamCellCount: float= A variable that determines how far a user can pan away from the level scene before being clamped. -
moveSpeed: float= A variable that determines how fast a user can move around the level scene when using WASD. -
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= A variable that determines how fast a user can zoom in or out the camera. -
maxZoomOut: float= A variable that determines how far a user can zoom out. -
maxZoomIn: float= A variable that determines how close a user can zoom in. -
playZoom: float= A variable that determines how zoomed a camera is on the player. Set in level settings. -
followSpeed: float= A variable that determines how quickly the camera follows the player as a percentage. Set in level settings. -
deadzone: float= A variable that determines how far the player can move outside the centre of the screen before the camera follows. Set in level settings. -
cameraPlayClamp: bool= A variable that determines if the camera is clamped into the level bounds during play or not. Set in level settings. -
gridLines: TileMapLayer= An exported variable for the grid lines 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. -
func camera_encloses_roam(roamingBounds: Rect2) -> bool: Returns if the camera fully encloses the level bounds as a rect. -
func get_camera_rect() -> Rect2: Returns the camera rect -
func get_min_zoom_to_fit_roam() -> float: Returns the minimum zoom to fit the roaming area.
List and description of upcoming work/risks.
Future Work:
- None
Risks:
- No known risks.
- System is single-node for simplicity
- State switching is handled externally by
MasterManager - Code follows modular function separation for readability
- Edge scrolling has been removed
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