37 lines
1.0 KiB
GDScript
37 lines
1.0 KiB
GDScript
extends Node2D
|
|
|
|
# To change the zoom
|
|
@export var grid: Resource
|
|
|
|
@export var CameraSpeedMult = 2
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready() -> void:
|
|
pass # Replace with function body.
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(delta: float) -> void:
|
|
if Input.is_action_pressed("MoveUp"):
|
|
_moveCamera(Vector2.UP)
|
|
if Input.is_action_pressed("MoveDown"):
|
|
_moveCamera(Vector2.DOWN)
|
|
if Input.is_action_pressed("MoveLeft"):
|
|
_moveCamera(Vector2.LEFT)
|
|
if Input.is_action_pressed("MoveRight"):
|
|
_moveCamera(Vector2.RIGHT)
|
|
|
|
if Input.is_action_just_released("ZoomIn"):
|
|
_zoomCamera(Vector2.ONE)
|
|
if Input.is_action_just_released("ZoomOut"):
|
|
_zoomCamera(-Vector2.ONE)
|
|
|
|
func _moveCamera(direction: Vector2):
|
|
position += direction * CameraSpeedMult
|
|
grid.setCameraPosition($SmartCamera2D.position)
|
|
grid.setScreenCenter($SmartCamera2D.get_screen_center_position())
|
|
|
|
func _zoomCamera(direction: Vector2):
|
|
$SmartCamera2D.zoom += direction
|
|
grid.setCameraZoom($SmartCamera2D.zoom)
|