So, I am trying to implement a selection indicator (an orange square that appears around the Selected sprite) and I came up with the idea of instancing that selection indicator at the position of my selected node (I know I can use shaders but as of now, that's above my understanding I don't want to rush.)
So here is my code:
extends Area2D
var selected = false
onready var selection = preload("res://SelectionIndicator.tscn")
func _input_event(viewport, event, shape_idx):
if event is InputEventMouseButton \
and event.button_index == BUTTON_LEFT \
and event.is_pressed():
self.on_click()
func on_click():
selected = not selected
if selected:
var selection_instance = selection.instance()
selection_instance.position = position
get_parent().add_child(selection_instance)
else:
# I want to hide the selection indicator when the Area2D is unselected
So, I got the selection thing working, However, I am not able to figure out how to unselect and hide the Selection indicator, I used queue.free() tried also remove_child(), Nothing seems to be working, I am pretty sure I am missing something simple, Any help is appreciated!
P.S: The Selection Indicator is a Sprite.