31 lines
823 B
GDScript
31 lines
823 B
GDScript
extends Camera2D
|
|
|
|
@export var speed := 500 # prędkość przesuwania
|
|
@export var zoom_speed := 0.5 # prędkość zoomu
|
|
|
|
func _process(delta):
|
|
var move = Vector2.ZERO
|
|
|
|
# przesuwanie WSAD / strzałki
|
|
if Input.is_action_pressed("map_move_right"):
|
|
move.x += 1
|
|
if Input.is_action_pressed("map_move_left"):
|
|
move.x -= 1
|
|
if Input.is_action_pressed("map_move_down"):
|
|
move.y += 1
|
|
if Input.is_action_pressed("map_move_up"):
|
|
move.y -= 1
|
|
|
|
position += move.normalized() * speed * delta
|
|
|
|
# zoom
|
|
if Input.is_action_pressed("zoom_in"): # np. Q
|
|
zoom -= Vector2(zoom_speed, zoom_speed) * delta
|
|
if Input.is_action_pressed("zoom_out"): # np. E
|
|
zoom += Vector2(zoom_speed, zoom_speed) * delta
|
|
|
|
# ograniczenie minimalnego i maksymalnego zoomu
|
|
zoom.x = clamp(zoom.x, 0.1, 3)
|
|
zoom.y = clamp(zoom.y, 0.1, 3)
|
|
|