-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMapViewCamera.gd
More file actions
38 lines (29 loc) · 1.09 KB
/
MapViewCamera.gd
File metadata and controls
38 lines (29 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
extends Camera2D
@export var camera_reset_point: Marker2D
var zoom_speed = 0.1
func _unhandled_input(event):
if event is InputEventMouseButton:
get_viewport().gui_release_focus()
if event.button_index == MOUSE_BUTTON_WHEEL_UP and event.pressed:
zoom += zoom * zoom_speed
if event.button_index == MOUSE_BUTTON_WHEEL_DOWN and event.pressed:
zoom -= zoom * zoom_speed
if event is InputEventMouseMotion:
if Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT) or Input.is_mouse_button_pressed(MOUSE_BUTTON_MIDDLE):
position -= (event.relative / zoom.x)
func _process(delta):
var input_direction = Input.get_vector("left", "right", "up", "down")
if input_direction != Vector2(0, 0):
position += (input_direction * 500 / zoom.x) * delta
if Input.is_action_pressed("zoom_in"):
_on_main_window_zoom(0.5)
if Input.is_action_pressed("zoom_out"):
_on_main_window_zoom(-0.5)
func _on_main_window_zoom(amt):
zoom += zoom * amt * zoom_speed
func _on_main_window_reset_camera():
zoom = Vector2(1, 1)
if camera_reset_point:
position = camera_reset_point.position
else:
position = Vector2(0, 0)