Trying new stuff with the camera and grid. I want to be able to move a unit but there is a problem with the grid at the moment. I am now trying to implement a new way of handling the camera, maybe then I can move on to moving units...
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
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.
|
||||
@@ -8,15 +13,24 @@ func _ready() -> void:
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
if Input.is_action_pressed("MoveUp"):
|
||||
global_position += Vector2.UP * 2
|
||||
_moveCamera(Vector2.UP)
|
||||
if Input.is_action_pressed("MoveDown"):
|
||||
global_position += Vector2.DOWN * 2
|
||||
_moveCamera(Vector2.DOWN)
|
||||
if Input.is_action_pressed("MoveLeft"):
|
||||
global_position += Vector2.LEFT * 2
|
||||
_moveCamera(Vector2.LEFT)
|
||||
if Input.is_action_pressed("MoveRight"):
|
||||
global_position += Vector2.RIGHT * 2
|
||||
_moveCamera(Vector2.RIGHT)
|
||||
|
||||
if Input.is_action_just_released("ZoomIn"):
|
||||
$SmartCamera2D.zoom += Vector2.ONE
|
||||
_zoomCamera(Vector2.ONE)
|
||||
if Input.is_action_just_released("ZoomOut"):
|
||||
$SmartCamera2D.zoom -= Vector2.ONE
|
||||
_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)
|
||||
|
||||
@@ -9,6 +9,11 @@ script = ExtResource("1_ig7ij")
|
||||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="SmartCamera2D" type="Camera2D" parent="."]
|
||||
limit_left = 0
|
||||
limit_top = 0
|
||||
limit_right = 800
|
||||
limit_bottom = 480
|
||||
limit_smoothed = true
|
||||
position_smoothing_enabled = true
|
||||
script = ExtResource("2_du7i2")
|
||||
target = NodePath("..")
|
||||
|
||||
Reference in New Issue
Block a user