Reputation: 69
Is it possible to check if a custom shape has been clicked. For instance, how would I check if a piano key, which is not a regular shape, has been clicked. I would assume that you would make an area 2D and make a Collision Polygon 2D, which has your shape, as a child, Then you would send a signal to a script if their was input, and the script would check if it was a click and respond accordingly. I tried this but it is not working. Below is my code. Any help is much appreciated!
func _on_Collision_input_event(viewport, event, shape_idx):
if event is InputEventMouseButton:
if event.is_pressed:
$"RadioCPressed".show()
print("Object Clicked")
else:
$"RadioCPressed".hide()
Upvotes: 1
Views: 2794
Reputation: 40325
You have a typo, it should be event.is_pressed()
not event.is_pressed
. It must be giving you an error on run time.
Assuming it is not giving you an error, it probably means the method is not running at all (You can use a print or breakpoint at the start of the method to confirm). Also, double check you connected the signal. And make sure the Area has input_pickable
set to true
.
Something else you need to consider if whether or not there is something else getting the input. A common case is that people will use a ColorRect
or TextureRect
for background, and leave it with mouse_filter
set to Stop (which is the default). Even if it is in the background, you need to set mouse_filter
to Ignore, because Controls take priority over other nodes for input. See Using InputEvent.
Upvotes: 2