Jump to content

Distance between a sprite and the closest sprite in a group

Recommended Posts


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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...