Find GameObject at x, y

When I click an interactive I get a reference to that GameObject. Now I would like to find a GameObject at some coordinates x, y, without clicking it. How can I do that?

You have to search them. A bit similar to Test intersection of two game objects (Phaser 3) with rectangle.contains(x, y).

Hm… getBounds() returns a rectangle. That is not good enough. The objects I want to test are polygons and are right next to each other. Bounding rectangles would surely yield false results: The bounding rectangle might cover an area that is not actually part of the polygon, but part of another polygon.

Clicking an interactive polygon however yields pixel perfect results, as far as I can tell. How does that work?

Ok, I found there is also a Phaser.Geom.Polygon which provides a contains() method. And I can get to it via the geom attribute. Nice.

And I guess it makes sense to narrow the list to test with the polygon first via testing with bounds, because presumably testing with a rectangle is a lot faster than with a polygon.

I might want to run tests for up to 20 coordinates, each testing about 50 polygons. Is this feasible to do in the update method? Or would this significantly slow down the framerate?