Jump to content

Destroying a matter.js rectangle body


Recommended Posts

Hi all

I'm creating a matter.js rectangle body with the following code:

let wireRect = this.matter.add.rectangle(w.x, w.y, this.wireLength, 10, { 
            restitution: 0.9,
            isSensor: true,
            angle: angle

I then later need to remove it from the game.

wireRect.destroy(); returns an error "wireRect.destroy is not a function".  I have another game in which I am using this.matter.add.image(XXX) and the .destroy() method works fine on those.

So I tried:

this.matter.world.remove(this.matter.world, wireRect);

That doesn't seem to work either.

I can see matter.body documentation https://photonstorm.github.io/phaser3-docs/MatterJS.Body.html, but can't see how I would find the correct destroy method for it.

Any ideas welcome please! 

Thanks :)

Link to comment
Share on other sites

Thanks very much.  However, the objects still accept collisions etc and also still show up in debug mode.  Have you had this working successfully?

Just out of interest, how did you get the "Phazer patron" badge to display (I am a patron, but it's not showing for me)?

Link to comment
Share on other sites

You are a legend, thanks.  I can replicate this working in the example page you sent too :)  Will have a go at implementing in my code as soon as I have a chance.

Thanks very much!  Greatly appreciated.

Link to comment
Share on other sites

  • 2 weeks later...

  • Recently Browsing   0 members

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