From 30dda882eb37df92e593a0e16ca60db31414c2e0 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Tue, 8 Jan 2019 11:50:21 +0000 Subject: [PATCH] `Matter.TileBody.setFromTileCollision` no longer checks if the shape is concave or convex before modifying the vertices, as the update to the Matter.js lib in 3.12 stopped this from working with Tiled collision shapes. --- CHANGELOG.md | 1 + src/physics/matter-js/MatterTileBody.js | 14 ++++++++------ src/physics/matter-js/World.js | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 037b224bc..d591ee057 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -211,6 +211,7 @@ one set of bindings ever created, which makes things a lot cleaner. * `WebGLRenderer.preRender` now calls `gl.clearColor` in order to restore the background clear color in case something, like a Render Texture, has changed it. * `Map.set` will now update an existing value if you provide it with a key that already exists within the Map. Previously, if you tried to set the value of a key that existed it would be skipped. * `MatterSprite` would set its `type` property to be `Image`. It now sets it to be `Sprite` as it should do. +* `Matter.TileBody.setFromTileCollision` no longer checks if the shape is concave or convex before modifying the vertices, as the update to the Matter.js lib in 3.12 stopped this from working with Tiled collision shapes. ### Bug Fixes diff --git a/src/physics/matter-js/MatterTileBody.js b/src/physics/matter-js/MatterTileBody.js index e22e46a76..260ea8568 100644 --- a/src/physics/matter-js/MatterTileBody.js +++ b/src/physics/matter-js/MatterTileBody.js @@ -220,12 +220,14 @@ var MatterTileBody = new Class({ // matter expects points to be relative to the center of mass. This only applies to // convex shapes. When a concave shape is decomposed, multiple parts are created and // the individual parts are positioned relative to (ox, oy). - if (Vertices.isConvex(points)) - { - var center = Vertices.centre(vertices); - ox += center.x; - oy += center.y; - } + // + // Update: 8th January 2019 - the latest version of Matter needs the Vertices adjusted, + // regardless if convex or concave. + + var center = Vertices.centre(vertices); + + ox += center.x; + oy += center.y; body = Bodies.fromVertices(ox, oy, vertices, options); } diff --git a/src/physics/matter-js/World.js b/src/physics/matter-js/World.js index 0a8fda1e5..862043dee 100644 --- a/src/physics/matter-js/World.js +++ b/src/physics/matter-js/World.js @@ -537,7 +537,7 @@ var World = new Class({ convertTilemapLayer: function (tilemapLayer, options) { var layerData = tilemapLayer.layer; - var tiles = tilemapLayer.getTilesWithin(0, 0, layerData.width, layerData.height, {isColliding: true}); + var tiles = tilemapLayer.getTilesWithin(0, 0, layerData.width, layerData.height, { isColliding: true }); this.convertTiles(tiles, options);