Skip to content

Commit cc55ee7

Browse files
committed
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 phaserjs#4206
1 parent bbe95d9 commit cc55ee7

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ one set of bindings ever created, which makes things a lot cleaner.
230230
* `Utils.Array.MoveUp` wouldn't let you move an array element to the top-most index in the array. This also impacted `Container.moveUp`.
231231
* 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.
232232
* 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)
233+
* 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)
233234

234235
### Examples and TypeScript
235236

src/physics/matter-js/components/Transform.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ var Transform = {
8484

8585
set: function (value)
8686
{
87-
var factor = 1 / this._scaleX;
88-
87+
var factorX = 1 / this._scaleX;
88+
var factorY = 1 / this._scaleY;
89+
8990
this._scaleX = value;
9091

9192
if (this._scaleX === 0)
@@ -98,7 +99,7 @@ var Transform = {
9899
}
99100

100101
// Reset Matter scale back to 1 (sigh)
101-
Body.scale(this.body, factor, this._scaleY);
102+
Body.scale(this.body, factorX, factorY);
102103

103104
Body.scale(this.body, value, this._scaleY);
104105
}
@@ -121,7 +122,8 @@ var Transform = {
121122

122123
set: function (value)
123124
{
124-
var factor = 1 / this._scaleY;
125+
var factorX = 1 / this._scaleX;
126+
var factorY = 1 / this._scaleY;
125127

126128
this._scaleY = value;
127129

@@ -134,7 +136,7 @@ var Transform = {
134136
this.renderFlags |= _FLAG;
135137
}
136138

137-
Body.scale(this.body, this._scaleX, factor);
139+
Body.scale(this.body, factorX, factorY);
138140

139141
Body.scale(this.body, this._scaleX, value);
140142
}

0 commit comments

Comments
 (0)