Skip to content

Commit 578fe59

Browse files
committed
Add scale support to MatterTileBody
1 parent 64d1725 commit 578fe59

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

src/physics/matter-js/MatterTileBody.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ var MatterTileBody = new Class({
154154
if (!HasValue(options, "isStatic")) { options.isStatic = true; }
155155
if (!HasValue(options, "addToWorld")) { options.addToWorld = true; }
156156

157+
var sx = this.tile.tilemapLayer.scaleX;
158+
var sy = this.tile.tilemapLayer.scaleY;
157159
var tileX = this.tile.getLeft();
158160
var tileY = this.tile.getTop();
159161
var collisionGroup = this.tile.getCollisionGroup();
@@ -163,10 +165,10 @@ var MatterTileBody = new Class({
163165
for (var i = 0; i < collisionObjects.length; i++)
164166
{
165167
var object = collisionObjects[i];
166-
var ox = tileX + object.x;
167-
var oy = tileY + object.y;
168-
var ow = object.width;
169-
var oh = object.height;
168+
var ox = tileX + (object.x * sx);
169+
var oy = tileY + (object.y * sy);
170+
var ow = object.width * sx;
171+
var oh = object.height * sy;
170172
var body = null;
171173

172174
if (object.rectangle)
@@ -182,7 +184,7 @@ var MatterTileBody = new Class({
182184
// Polygons and polylines are both treated as closed polygons
183185
var originalPoints = object.polygon ? object.polygon : object.polyline;
184186
var points = originalPoints.map(function (p) {
185-
return { x: p[0], y: p[1] };
187+
return { x: p[0] * sx, y: p[1] * sy };
186188
});
187189
var vertices = Vertices.create(points);
188190

0 commit comments

Comments
 (0)