How would I send a signal from an Area2D when the input is a left-click?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By System_Error

Hi all. Trying to get something to work, but I don’t really know how to do it.

What I have is a Node, with a child(Area2D) and grandchild(CollisionShape2D). The whole scene will be instanced into the main scene. What I’d like to do is send a signal to another instanced scene when a player left-clicks in the Area2D’s sector.

:bust_in_silhouette: Reply From: rojekabc

Area2D extends CollisionObject2D. You may use _input_event

extends Area2d
signal your_signal

func _on_Area2D_input_event( viewport, event, shape_idx ):
if (event.type == InputEvent.MOUSE_BUTTON && event.pressed):
    emit_signal("your_signal")

But you have to connect to signal from this object to listen it. You may also try to put such signal in some upper/common level (for example your main scene) and then emit it from this event catching. main_scene_node.emit_signal(“your_signal”)

Hey, would you clarify what this would do? I’m having a hard time understanding it.

System_Error | 2018-12-20 02:03