camera no move out of window
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user