Cursor example
This commit is contained in:
@@ -2,9 +2,21 @@ class_name BattleCursor extends Control
|
||||
|
||||
@export var cursor:PackedScene
|
||||
|
||||
func setCursors(targets:Array[BattleSingleton.BattlePosition]) -> void:
|
||||
func setCursors(battleScene:BattleScene, targets:Array[BattleSingleton.BattlePosition]) -> void:
|
||||
clearCursors()
|
||||
|
||||
for target in targets:
|
||||
var fighterScene = battleScene.getFighterSceneAtPosition(target)
|
||||
if fighterScene == null:
|
||||
continue
|
||||
|
||||
var cursorInstance = cursor.instantiate()
|
||||
add_child(cursorInstance)
|
||||
|
||||
# Convert world position to screen space
|
||||
var screenPos = battleScene.get_viewport().get_camera_3d().unproject_position(fighterScene.global_transform.origin)
|
||||
cursorInstance.position = screenPos
|
||||
|
||||
func clearCursors() -> void:
|
||||
# Clear all children (cursors).
|
||||
for child in get_children():
|
||||
|
||||
@@ -5,8 +5,7 @@
|
||||
|
||||
[node name="BattleCursor" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 0
|
||||
offset_right = 11.0
|
||||
offset_bottom = 11.0
|
||||
size_flags_horizontal = 0
|
||||
size_flags_vertical = 0
|
||||
script = ExtResource("1_wsiei")
|
||||
cursor = ExtResource("2_6yv4v")
|
||||
|
||||
@@ -1,6 +1,15 @@
|
||||
[gd_scene format=3 uid="uid://br2rs8skcn72l"]
|
||||
|
||||
[node name="Control" type="ColorRect"]
|
||||
offset_right = 8.0
|
||||
offset_bottom = 8.0
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -4.0
|
||||
offset_top = -4.0
|
||||
offset_right = 4.0
|
||||
offset_bottom = 4.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
color = Color(1, 0.478431, 1, 1)
|
||||
|
||||
Reference in New Issue
Block a user