Using matter js event listeners after world destroyed

Hi all,

I have a tilemap in my Phaser 3 + matter js game.

I make the tilemap with var mapObj = this.make.tilemap({'key': 'mainMap'});

I use this.matter.world.convertTilemapLayer to make the tilemap layers collidable.

What I’m trying to do is remove the tilemap and load a different one in it’s place.

To do this I destroy the map with mapObj.destroy();. Then I made a new tilemap with mapObj = this.make.tilemap({'key': 'mainMap'});.

This all worked untill I noticed that the matter js bodies on the tilemap were bouncing around as if the floor was lava.

So I tried to destroy the matter js connection with this.matter.world.destroy();. And fixed the floor is lava problem but then I noticed that the collisionstart event wasn’t firing anymore.

I was setting the event with:

this.matter.world.on('collisionstart', function (evt, bodyA, bodyB) {
    console.log(1);
});

And so I re-set the event after the tilemap was created but the event still wasn’t firing :frowning:

I suspect it’s a problem with the way I’m removing the matterjs connection to the tilemap but I’m not sure of any other way to do it.

Summary: I’m using game.matter.world.destroy(); to remove my tilemap from matter js but then the event listeners don’t work.

Thanks in advance.