shtanton Posted May 10, 2016 Share Posted May 10, 2016 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 More sharing options...
drhayes Posted May 10, 2016 Share Posted May 10, 2016 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 More sharing options...
shtanton Posted May 17, 2016 Author Share Posted May 17, 2016 Thanks for the feedback, I've implemented the iteration using forEach but the event I was talking about would be triggered when a sprite comes within a certain distance of another sprite Link to comment Share on other sites More sharing options...
Recommended Posts