34 lines
882 B
GDScript
34 lines
882 B
GDScript
extends Camera2D
|
|
|
|
var PAN_SPEED = 30
|
|
var is_panning
|
|
var pan_start = Vector2.ZERO
|
|
# 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):
|
|
if Input.is_action_pressed("ui_left"):
|
|
position.x -= 3
|
|
if Input.is_action_pressed("ui_right"):
|
|
position.x += 3
|
|
if Input.is_action_pressed("ui_up"):
|
|
position.y -= 3
|
|
if Input.is_action_pressed("ui_down"):
|
|
position.y += 3
|
|
|
|
if is_panning:
|
|
var pan_delta = (pan_start - get_viewport().get_mouse_position()) / get_zoom() * delta * PAN_SPEED
|
|
position += pan_delta
|
|
pan_start = get_viewport().get_mouse_position()
|
|
pass
|
|
|
|
func _input(event):
|
|
if Input.is_mouse_button_pressed(MOUSE_BUTTON_MIDDLE):
|
|
is_panning = true
|
|
pan_start = event.position
|
|
else:
|
|
is_panning = false
|