How to update the color of an already rendered Body in Matterjs

626 views Asked by At

I have a Body that is already added to the world. I want to update the color.

var ball = Bodies.circle(xPosition, yPosition, 25, {
  force: {
    x: rand(-0.0005, 0.01),
    y: -0.01
  },
  restitution: 0.75,
  render: {
    fillStyle: '#A87FB5',
  },
});



World.add(world, [
  ball,
]);

I have tried:

Body.set(ball, fillStyle, '#754C82');
Body.set(ball, render.fillStyle, '#754C82');
Body.set(ball, {render: {fillStyle: '#754C82'}});

I suspect I'm using the wrong approach. Unless I've overlooked it, I can't find anything in the documentation about how to update this.

1

There are 1 answers

0
JonathanW On BEST ANSWER

Apparently that is one of the properties that you can just reach in and change

ball.render.fillStyle = '#754C82';