0 votes

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.

in Engine by (197 points)

1 Answer

0 votes

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")

by (164 points)

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.