jorbascrumps Posted October 28, 2018 Share Posted October 28, 2018 Hi all, I've used Phaser.Physics.Matter.World#convertTilemapLayer to create physics bodies for tiles in my Tilemap. This is working beautifully ?What I'm wondering now is how can I update the world after updates to the Tilemap (say, addition or removal of a Tile)? Thanks Link to comment Share on other sites More sharing options...
jorbascrumps Posted November 2, 2018 Author Share Posted November 2, 2018 Anybody? Link to comment Share on other sites More sharing options...
Telinc1 Posted November 4, 2018 Share Posted November 4, 2018 Judging solely from the source code, convertTilemapLayer creates a MatterTileBody for each colliding tile in the layer. The MatterTileBody constructor destroys the tile's existing body, so you could theoretically just call convertTilemapLayer again to recreate all of the layer's physics bodies. I can immediately see two possible problems with this, however. For one, convertTilemapLayer only processes colliding tiles, so it won't remove the body from a colliding tile which became non-colliding. In that case, you'd need to get the tile and manually call `tile.physics.matterBody.destroy()`... or you could just do that for the whole layer before calling convertTilemapLayer. Another problem I see is that you could end up needlessly recreating a lot of tile bodies, so I'd suggest looking at the source code of convertTilemapLayer (line 537 as of 4c4421c) and the related convertTiles (line 559 as of the same commit) method in the Matter World to update only a small region of tiles (in essence, you'd need to make a clone of convertTilemapLayer but with a changed call to getTilesWithin). I don't use Matter physics in my projects so I've got no idea if this is the best way to do this or if it'll even work, but it doesn't hurt to try if no one else has suggestions. Link to comment Share on other sites More sharing options...
jorbascrumps Posted November 4, 2018 Author Share Posted November 4, 2018 Thank you for the detailed response, @Telinc1! I've been doing some digging and came across this Labs example which does what I need. Following that example I've been able to remove a Tile's body with `tile.physics.matterBody.destroy()`. However, for some reason despite having Tiles underneath the one I've removed, my player falls right through. My assumption at this point is that it's something wrong with how I've setup my character.. Link to comment Share on other sites More sharing options...
Recommended Posts