Jump to content

Display Object under point


afowler2k
 Share

Recommended Posts

I am building a small GUI using Phaser and need to be able to add a sprite arbitrarily to the world.

I would like the added sprite to have the same parent as the sprite the pointer is over.

What I am struggling with is how to find the sprite that is visible directly under the pointer.

I have tried iterating through all the children on the world looking for everything who's bounds contain that point, but then I don't know how to figure out which of those is actually the top most visible on the screen.

Is there an easier way to get the sprite under the pointer?

Link to comment
Share on other sites

You see, I'm asking because rather than looking for help accomplishing specific goal, you're looking for help accomplishing one very specific step on your way to the goal. But it might so happen that the whole path you chose is sub-optimal and thus the whole topic is moot. If you describe the goal you want to achieve, people might suggest better ways of getting there.

I would keep an array of sprites that can be duplicated, sorted by depth in descending order, so I could iterate over them all and the first one to pass hit test is the one I'm looking for. Of course that would be redundant if you can do that with any sprite from a specific group. If there's really many of them, I'd also used spatial partitioning of some sort because too long lists create too big processing burden.

Also keep in mind that sprite hit area is rectangle. So you may need to individually assign proper hit testing polygons to them.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...