-
Notifications
You must be signed in to change notification settings - Fork 0
/
BuildingCamera.gd
47 lines (37 loc) · 1.1 KB
/
BuildingCamera.gd
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
39
40
41
42
43
44
45
46
47
extends Camera2D
var _target_zoom: float = 1.0
const MIN_ZOOM: float = 0.5
const MAX_ZOOM: float = 2.0
const ZOOM_INCREMENT: float = 0.2
const ZOOM_RATE: float = 8.0
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func _physics_process(delta):
zoom = lerp(
zoom,
_target_zoom * Vector2.ONE,
ZOOM_RATE * delta
)
set_physics_process(
not is_equal_approx(zoom.x, _target_zoom)
)
func _input(event: InputEvent):
if event is InputEventMouseMotion:
if event.button_mask == MOUSE_BUTTON_MASK_RIGHT:
position -= event.relative
if event is InputEventMouseButton:
if event.is_pressed():
if event.button_index == MOUSE_BUTTON_WHEEL_UP:
zoom_in()
if event.button_index == MOUSE_BUTTON_WHEEL_DOWN:
zoom_out()
func zoom_out():
_target_zoom = max(_target_zoom - ZOOM_INCREMENT, MIN_ZOOM)
set_physics_process(true)
func zoom_in():
_target_zoom = min(_target_zoom + ZOOM_INCREMENT, MAX_ZOOM)
set_physics_process(true)