- Edited
So, I have a set up where I use signals to connect the mouse click to "select" (I am a pragmatist not super strong in my programming, sorry if this is the worst way to do what I am trying). I have succeeded in "clicking" the objects and have the selector sprite appear, and it will also disappear as I want when I click another object, however I want it to disappear when I click the same object again.
I chain signals, not sure if this is the best way to do it, maybe it would be better to go directly, while writing this I thought of a way to skip the middle man that should work, I might try that while waiting for responses, however, that doesn't fix my original problem.
My problem is I haven't figured out how to make it disappear when I click it again, this could be due to my frankenstein signal code, or the way I have it set up, is there a way that I can make the "select" sprite go invisible when I click the same object again. Here is the code...
#Code on child that is emitting a signal after receiving a signal from the Area2D node that is its child
signal selection(source)
func _ready():
self.add_to_group("spaceships")
find_child("Selection").add_to_group("selected")
func mouse_select(_viewport, event, _shape_idx):
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
if event.pressed:
emit_signal("selection", self)
else:
return
#On parent node that controls
func _ready():
for ship in arrShip:
ship.connect("selection", selection)
func selection(source):
var selected = get_tree().get_nodes_in_group("selected")
var origin = get_node(get_path_to(source.find_child("Selection")))
for selector in selected:
selector.visible = false
if origin.visible == false:
origin.visible = true