diff --git a/CHANGELOG.md b/CHANGELOG.md index 5fb8b8e8b..5ebb7a668 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -149,6 +149,7 @@ The Tile Sprite Game Object has been given an internal overhaul to make it more * The calls to `DistanceBetween` have been replaced with `DistanceSquared` in the `closest` and `furthest` functions within Arcade Physics (thanks @Mursaat) * The RandomDataGenerator will now create a default random seed if you instantiate your own version of the class (instead of using `Phaser.Math.RND`) and don't provide a seed for it (thanks michaeld) * The Tilemap `createFromObjects` method will now add custom properties to the Game Objects. It works by checking if the property exists or not, and if not, it sets it in the Game Objects Data Manager (thanks @scalemailted @samme) +* In Matter.js if you scaled a Body it would only scale correctly once, due to the way Matter handles scaling internally. We now automatically reset the Matter scale before applying the new value, which allows you to keep the Phaser and Matter object scales in sync. Fix #3785 #3951 (thanks @bergben) ### Game Config Resolution Specific Bug Fixes diff --git a/src/physics/matter-js/components/Transform.js b/src/physics/matter-js/components/Transform.js index 457fd0ce4..8f9bdf230 100644 --- a/src/physics/matter-js/components/Transform.js +++ b/src/physics/matter-js/components/Transform.js @@ -84,6 +84,8 @@ var Transform = { set: function (value) { + var factor = 1 / this._scaleX; + this._scaleX = value; if (this._scaleX === 0) @@ -95,6 +97,9 @@ var Transform = { this.renderFlags |= _FLAG; } + // Reset Matter scale back to 1 (sigh) + Body.scale(this.body, factor, this._scaleY); + Body.scale(this.body, value, this._scaleY); } @@ -116,6 +121,8 @@ var Transform = { set: function (value) { + var factor = 1 / this._scaleY; + this._scaleY = value; if (this._scaleY === 0) @@ -127,6 +134,8 @@ var Transform = { this.renderFlags |= _FLAG; } + Body.scale(this.body, this._scaleX, factor); + Body.scale(this.body, this._scaleX, value); } @@ -273,9 +282,14 @@ var Transform = { if (x === undefined) { x = 1; } if (y === undefined) { y = x; } + var factorX = 1 / this._scaleX; + var factorY = 1 / this._scaleY; + this._scaleX = x; this._scaleY = y; + Body.scale(this.body, factorX, factorY, point); + Body.scale(this.body, x, y, point); return this;