The Matter.Mass.centerOfMass component property now returns the pre-calculated Body centerOfMass property, which is much more accurate than the previous bounds offset value.

This commit is contained in:
Richard Davey 2019-12-09 12:49:55 +00:00
parent 9f012ebf86
commit 53314ca435

View file

@ -51,6 +51,10 @@ var Mass = {
/** /**
* The body's center of mass. * The body's center of mass.
*
* Calling this creates a new `Vector2 each time to avoid mutation.
*
* If you only need to read the value and won't change it, you can get it from `GameObject.body.centerOfMass`.
* *
* @name Phaser.Physics.Matter.Components.Mass#centerOfMass * @name Phaser.Physics.Matter.Components.Mass#centerOfMass
* @type {Phaser.Math.Vector2} * @type {Phaser.Math.Vector2}
@ -63,7 +67,7 @@ var Mass = {
get: function () get: function ()
{ {
return new Vector2(this.body.render.sprite.xOffset * this.width, this.body.render.sprite.yOffset * this.height); return new Vector2(this.body.centerOfMass.x, this.body.centerOfMass.y);
} }
} }