Everything is fine, except that I need to find when the mouse’s cursor is only inside the polygon. Then I thought about triangulate the polygon and find out if the mouse’s cursor is “in” a triangle or not (and, of course, parse the triangles within a for/while loop).
So I was wondering if there’s another way to do this. Similar to the “mousepick_test” from the 3D demos, but in 2D and maybe using Polygon2D as a shape.
Here’s an example of a shape of the button that I need:
Yes, if that’s the approach you want to take, you can use the pickable events with the collision detection of physics bodies to detect mouse events. When input propagates, at the end it will cast a ray into the viewport, and pickables will test for them.
So you would make a physics body of some kind, and instead put a CollisionPolygon2D as the child.
Make sure the physics body’s Is Pickable property is flagged to true.
In GDScript you then would add the _input_event() function, and you will get all the mouse events as it “collides” with the polygon collision shape.