camera no move out of window

This commit is contained in:
2024-09-01 12:54:18 +02:00
parent 21b694d4b6
commit f9e1a56615
3 changed files with 15 additions and 6 deletions

View File

@@ -1,9 +1,10 @@
extends Camera2D
const MOVEMENT_SPEED = 500
const RUN_MULT = 2
const ZOOM_SPEED = 10
const ZOOM_WINDOW = [0.5, 2]
const SCREEN_BORDER_THRESHOLD = 10
const SCREEN_BORDER_THRESHOLD = 40
var grabbing = false
var mouse_last_global_position = Vector2()
@@ -23,22 +24,22 @@ func _process(delta):
if (
Input.is_action_pressed("right")
or mouse_pos.x > viewport_size.x - SCREEN_BORDER_THRESHOLD
or mouse_pos.x > viewport_size.x - SCREEN_BORDER_THRESHOLD and mouse_pos.x <= viewport_size.x
) :
direction.x = 1
if (
Input.is_action_pressed("left")
or mouse_pos.x < 0 + SCREEN_BORDER_THRESHOLD
or mouse_pos.x < 0 + SCREEN_BORDER_THRESHOLD and mouse_pos.x >= 0
):
direction.x = -1
if (
Input.is_action_pressed("up")
or mouse_pos.y < 0 + SCREEN_BORDER_THRESHOLD
or mouse_pos.y < 0 + SCREEN_BORDER_THRESHOLD and mouse_pos.y >= 0
):
direction.y = -1
if (
Input.is_action_pressed("down")
or mouse_pos.y > viewport_size.y - SCREEN_BORDER_THRESHOLD
or mouse_pos.y > viewport_size.y - SCREEN_BORDER_THRESHOLD and mouse_pos.y <= viewport_size.y
):
direction.y = 1
@@ -54,6 +55,9 @@ func _process(delta):
movement += direction*MOVEMENT_SPEED*delta
if Input.is_action_pressed("run"):
movement *= RUN_MULT
move_camera_on_map(movement)
mouse_last_global_position = get_global_mouse_position()