Skip to content

Commit a98b3c3

Browse files
committed
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 phaserjs#3785 phaserjs#3951
1 parent ae01830 commit a98b3c3

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ The Tile Sprite Game Object has been given an internal overhaul to make it more
149149
* The calls to `DistanceBetween` have been replaced with `DistanceSquared` in the `closest` and `furthest` functions within Arcade Physics (thanks @Mursaat)
150150
* 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)
151151
* 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)
152+
* 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)
152153

153154
### Game Config Resolution Specific Bug Fixes
154155

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ var Transform = {
8484

8585
set: function (value)
8686
{
87+
var factor = 1 / this._scaleX;
88+
8789
this._scaleX = value;
8890

8991
if (this._scaleX === 0)
@@ -95,6 +97,9 @@ var Transform = {
9597
this.renderFlags |= _FLAG;
9698
}
9799

100+
// Reset Matter scale back to 1 (sigh)
101+
Body.scale(this.body, factor, this._scaleY);
102+
98103
Body.scale(this.body, value, this._scaleY);
99104
}
100105

@@ -116,6 +121,8 @@ var Transform = {
116121

117122
set: function (value)
118123
{
124+
var factor = 1 / this._scaleY;
125+
119126
this._scaleY = value;
120127

121128
if (this._scaleY === 0)
@@ -127,6 +134,8 @@ var Transform = {
127134
this.renderFlags |= _FLAG;
128135
}
129136

137+
Body.scale(this.body, this._scaleX, factor);
138+
130139
Body.scale(this.body, this._scaleX, value);
131140
}
132141

@@ -273,9 +282,14 @@ var Transform = {
273282
if (x === undefined) { x = 1; }
274283
if (y === undefined) { y = x; }
275284

285+
var factorX = 1 / this._scaleX;
286+
var factorY = 1 / this._scaleY;
287+
276288
this._scaleX = x;
277289
this._scaleY = y;
278290

291+
Body.scale(this.body, factorX, factorY, point);
292+
279293
Body.scale(this.body, x, y, point);
280294

281295
return this;

0 commit comments

Comments
 (0)