From 446083dd7349656bdd984837e2f92010fc28ab7e Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Tue, 16 Apr 2024 01:44:06 +0200 Subject: [PATCH] Create `Cursor` matching mouse position on every physics timestep --- scenes/game/cursor.gd | 11 +++++++++++ scenes/game/cursor.tscn | 6 ++++++ 2 files changed, 17 insertions(+) create mode 100644 scenes/game/cursor.gd create mode 100644 scenes/game/cursor.tscn diff --git a/scenes/game/cursor.gd b/scenes/game/cursor.gd new file mode 100644 index 0000000..79bcc35 --- /dev/null +++ b/scenes/game/cursor.gd @@ -0,0 +1,11 @@ +extends Node2D +class_name Cursor + +## A [Node2D] syncing its position with the mouse on each physics timestep. + + +@onready var game := MainGame.get_ancestor(self) + + +func _physics_process(_delta: float) -> void: + global_position = game.camera.get_global_mouse_position() diff --git a/scenes/game/cursor.tscn b/scenes/game/cursor.tscn new file mode 100644 index 0000000..e31c98e --- /dev/null +++ b/scenes/game/cursor.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3 uid="uid://col1q3elvkfwk"] + +[ext_resource type="Script" path="res://scenes/game/cursor.gd" id="1_1og6v"] + +[node name="Cursor" type="Node2D"] +script = ExtResource("1_1og6v")