Jump to content

Distance between a sprite and the closest sprite in a group


shtanton
 Share

Recommended Posts

Hi

I need to find the distance between a player sprite and the closest sprite to it in a group of sprites, I know this can be done by iterating through each of the sprites in the group and checking them individually however, I was hoping phaser had a built in way of accomplishing this.  Once the player is within a certain distance, it will die so if phaser has an event for this that will work as well.

Thanks for any help

Link to comment
Share on other sites

I don't know that Phaser has anything that would be more efficient than iterating over the children over the group. It does have those iteration methods, if you need them: forEach, forEachAlive, etc.

When you say "it will die so if phaser has an event for this", what do you mean? An event that is fired when a sprite dies? There's Phaser.Sprite.events.onKilled, but I'm not sure that's what you want?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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