## Recommended Posts

I just cannot figure out is distanceBetween calculating from anchor point or upper left corner of a sprite?

Is there a easy way to calculate distance between a single point and a whole sprite, not anchor point nor upper left corner but any point of that sprite?

##### Share on other sites

Generally, the X/Y of the object is used for calculations...

Looking at the source code for this function, it is the X/Y of the object... Changing the anchor doesn't matter to the calculation at all...

You can also use game.math.distance to get the distance between two points... It takes the individual coordinates instead of the whole object as arguments...
http://phaser.io/docs/2.6.2/Phaser.Math.html#distance

How do you mean "distance between a point and a whole sprite"..? Do you want a collection of distances for each pixel the sprite is taking up, or just the X/Y...?

##### Share on other sites

It calculates from obj.position, which is the anchor point. It will be the top left if the anchor is (0, 0).

For point-to-sprite-point calculations, you can use Phaser.Math#distance with x = sprite.left, sprite.centerX, sprite.right; y = sprite.top, sprite.centerY, sprite.bottom.