From 53314ca435b4e76a76926818c647a1ca43b0a5e2 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Mon, 9 Dec 2019 12:49:55 +0000 Subject: [PATCH] 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. --- src/physics/matter-js/components/Mass.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/physics/matter-js/components/Mass.js b/src/physics/matter-js/components/Mass.js index 1269cb1b5..2574ca3db 100644 --- a/src/physics/matter-js/components/Mass.js +++ b/src/physics/matter-js/components/Mass.js @@ -51,6 +51,10 @@ var 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 * @type {Phaser.Math.Vector2} @@ -63,7 +67,7 @@ var Mass = { 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); } }