Jump to content

How to refresh Matter world after Tilemap update?


jorbascrumps
 Share

Recommended Posts

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

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...