hexland/Scripts/GameCamera.gd

32 lines
664 B
GDScript3
Raw Normal View History

2022-08-23 14:12:59 -05:00
extends Camera2D
const ZOOM_SPEED = 0.2
var pan = false
func _process(_delta):
if Input.is_action_just_released("ui_zoom_in"):
zoom -= Vector2.ONE * ZOOM_SPEED
elif Input.is_action_just_released("ui_zoom_out"):
zoom += Vector2.ONE * ZOOM_SPEED
if Input.is_action_pressed("ui_pan"):
pan = true
else:
pan = false
func _input(event):
if event is InputEventMouseMotion:
if pan:
translate(-event.relative * zoom)
func get_corner(corner):
return $Corners.get_node(str(corner))
func place_corner(corner, item):
get_corner(corner).add_child(item)
func clear_corner(corner):
for child in get_corner(corner).get_children():
child.queue_free()