area2D work not right

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Timofey
func _on_Area2D_input_event(viewport, event, shape_idx):

the function is triggered only when the mouse button is released in it and at the same time if the pressed mouse button was entered from outside the object, and not in it.


How do you want the Area2D to work? Since a mouse button click is an input event, it looks like the signal is working.

Ertain | 2021-01-29 18:22

how then to check the mouse click on area2D?

Timofey | 2021-01-30 12:00

I realized that the color rect overlapped the collision body

Timofey | 2021-01-30 12:21

:bust_in_silhouette: Reply From: Trider

If you want to listen only to the left mouse button click, this is the code:

func _on_Area2D_input_event(viewport, event, shape_idx):
    if event is InputEventMouseButton:
        if event.button_index == BUTTON_LEFT and event.pressed:
            print("Left button was clicked at ", event.position)