Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Noe | |
Old Version | Published before Godot 3 was released. |
Hello,
I have different Area2Ds spawning in my scene and I want to detect when they get clicked. Actually I’m using the following script:
func _input_event(viewport, event, shape_idx):
if event.type == InputEvent.MOUSE_BUTTON \
and event.button_index == BUTTON_LEFT \
and event.pressed: clicked()
However if I have two Area2Ds overlapping, the two will detect the click. So does anyone have a good method to detect the click only on a “visible” object?
Thank you.
BTW here’s the actual scenario in my game:
I’ve had this issue as well and I’ve yet to find an elegant solution. I’ve tried “set_input_as_handled” without success. The best I’ve come up with is to use a boolean flag as a workaround. I test each object in order of importance for input. The first valid object sets the flag and completes its task. Subsequent objects check and see that the flag is set, and ignore the click. It’s not pretty but it works. I’d love to hear a neater solution, or better yet, have a Godot implemented “pickable only if visible” option for the Area2D node.
Michael Paul | 2017-10-26 10:45
I don’t think that your method will work because I’m instancing the objects. But thank you anyway
Noe | 2017-10-26 15:35