38 lines
1.0 KiB
GDScript
38 lines
1.0 KiB
GDScript
extends Camera2D
|
|
|
|
var zoom_speed=Vector2(.2,.2)
|
|
var scrolling=false;
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready():
|
|
pass # Replace with function body.
|
|
|
|
func _input(event):
|
|
if event is InputEventMouseButton:
|
|
if event.is_pressed():
|
|
if event.button_index==MOUSE_BUTTON_WHEEL_UP:
|
|
zoom+=zoom_speed
|
|
if event.button_index==MOUSE_BUTTON_WHEEL_DOWN:
|
|
zoom-=zoom_speed
|
|
if event.button_index==MOUSE_BUTTON_MIDDLE:
|
|
scrolling=true
|
|
if event.is_released():
|
|
if event.button_index==MOUSE_BUTTON_MIDDLE:
|
|
scrolling=false
|
|
if event is InputEventMouseMotion:
|
|
if scrolling:
|
|
offset-=event.velocity*0.1
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(delta):
|
|
if Input.is_action_pressed('move_up'):
|
|
offset.y -= 1
|
|
if Input.is_action_pressed('move_down'):
|
|
offset.y += 1
|
|
if Input.is_action_pressed('move_left'):
|
|
offset.x -= 1
|
|
if Input.is_action_pressed('move_right'):
|
|
offset.x += 1
|
|
# if Input.is_action_just_pressed('take'):
|
|
# drop()
|