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

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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