|Attention||Topic was automatically imported from the old Question2Answer platform.|
I have this code that makes a one of 2 (for this example, actually more) node’s sprite visible if the cursor enters it’s collision polygon area and makes it invisible when it exits. “Selected” is a sprite. All invisible by default.
func _on_Area1_mouse_entered(): $Heroes/Hero1/Area1/Selected.visible = true func _on_Area1_mouse_exited(): $Heroes/Hero1/Area1/Selected.visible = false func _on_Area2_mouse_entered(): $Heroes/Hero2/Area2/Selected.visible = true func _on_Area2_mouse_exited(): $Heroes/Hero2/Area2/Selected.visible = false
But now I want to make it so that a sprite that became visible would stay that way until another one gets visible. Only then the fist one would become invisible.
I do it like that:
var was_selected = null func _on_Area1_mouse_entered(): $Heroes/Hero1/Area1/Selected.visible = true if was_selected != null: was_selected.visible = false func _on_Area1_mouse_exited(): was_selected = $Heroes/Hero1/Area1/Selected func _on_Area2_mouse_entered(): $Heroes/Hero2/Area2/Selected.visible = true if was_selected != null: was_selected.visible = false func _on_Area2_mouse_exited(): was_selected = $Heroes/Hero2/Area2/Selected
When the cursor exits a node’s area it’s sprite’s path gets stored in a variable and when the cursor enters another area the previously stored sprite is made invisible.
Now if I move my mouse slowly everything works as intended. But if I move it fast then several nodes stay visible at the same time(I have more than 2 nodes) and others do not get visible or invisible if you hover over them. But if you enter-exit a few times then they switch how it was intended.
What did I miss here?