I'm new to Godot (just downloaded the software today and followed some beginner tutorials).
After working through everything up to the SceneTree section I thought I'd try to create something simple on my own as a test of what I'd learned so far. I thought Tic-Tac-Toe should be simple enough, but I've hit an issue pretty quickly: I cannot seem to get an
Area2D to detect mouse clicks.
TextureRect whose Texture is an image of a 3x3 grid, with ample white
space padding around the edges. This is the root node.
Area2D with Pickable set to On and one Collision Layer set. This is a child of Board
This is a child of ClickableArea with a
RectangleShape2D shape and has its Extents set so that it covers just the grid portion of Board (i.e. not the bounding whitespace).
Label which is a child of Board and is just used to display messages onscreen when certain events occur.
On ClickableArea2D under Node -> CollisionObject2D I've connected the input_event to itself, generating the method
_on_ClickableArea_input_event which has the following definition (code updated based on answer from user kidscancode):
func _on_ClickableArea_input_event(viewport, event, shape_idx):
get_node("../Message").text = "The message is not updated with this text"
if event is InputEventMouseButton \
and event.button_index == BUTTON_LEFT \
get_node("../Message").text = "CollisionShape2D Clicked"
As mentioned, clicks on the area defined by the
CollisionShape2D's extents do not register (even without checking that the event is a mouse button, that it is the left mouse button, or that the button is pressed).
Changing to a mouse entry event doesn't work, and I can detect mouse clicks on the root
TextureRect, so I believe the problem may be with the the area itself but I'm not sure.
Any help would really be appreciated.