diff --git a/CHANGELOG.md b/CHANGELOG.md index 449503351..68aa7c19a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -230,6 +230,7 @@ one set of bindings ever created, which makes things a lot cleaner. * `Utils.Array.MoveUp` wouldn't let you move an array element to the top-most index in the array. This also impacted `Container.moveUp`. * The Texture Tint Pipeline had a logic error that would cause every 2001st quad to either be invisible, or pick-up the texture of the 2000th quad by mistake. The `batchQuad` and `batchTri` methods how handle re-assigning the batch texture if they cause a batch flush as part of their process. * Rotating Sprites that used a Normal Map wouldn't rotate the normal map with it, causing the lighting effects to become irregular. The normal map vectors are now rotated correctly (thanks @sercant for the PR and @fazzamatazz and @ysraelJMM for the report) +* Changing `scaleX` or `scaleY` on a `MatterImage` or `MatterSprite` would cause the body scale to become distorted as the setters didn't use the correct factor when resetting the initial scale. Fix #4206 (thanks @YannCaron) ### Examples and TypeScript diff --git a/src/physics/matter-js/components/Transform.js b/src/physics/matter-js/components/Transform.js index 7478c74da..c87159e8a 100644 --- a/src/physics/matter-js/components/Transform.js +++ b/src/physics/matter-js/components/Transform.js @@ -84,8 +84,9 @@ var Transform = { set: function (value) { - var factor = 1 / this._scaleX; - + var factorX = 1 / this._scaleX; + var factorY = 1 / this._scaleY; + this._scaleX = value; if (this._scaleX === 0) @@ -98,7 +99,7 @@ var Transform = { } // Reset Matter scale back to 1 (sigh) - Body.scale(this.body, factor, this._scaleY); + Body.scale(this.body, factorX, factorY); Body.scale(this.body, value, this._scaleY); } @@ -121,7 +122,8 @@ var Transform = { set: function (value) { - var factor = 1 / this._scaleY; + var factorX = 1 / this._scaleX; + var factorY = 1 / this._scaleY; this._scaleY = value; @@ -134,7 +136,7 @@ var Transform = { this.renderFlags |= _FLAG; } - Body.scale(this.body, this._scaleX, factor); + Body.scale(this.body, factorX, factorY); Body.scale(this.body, this._scaleX, value); }