Changing shape of matterjs polygon

Hello,
I wonder what would be the best way to change the points of a matterjs polygon shape after creation?

  • For Phaser.GameObjects.Polygon I don’t see such an API
  • Manage a polygon body and a graphics shape separately (not sure how)
  • Remove GameObject and create slightly modified Polygon GameObject each time

I need only one such body, so performance shouldn’t be terrible either way.

Re-creating the GameObject proved to be working. Previous position, velocity and angular velocity can be copied to the new instance easily.

One trick was that the origin of the shape will change. setOrigin(0, 0) made the physics and graphics desynced, so instead I had to calculate the desired position from the new origin:

polygon.setPosition(x + polygon.displayOriginX, y + polygon.displayOriginY);