'How to change the texture of a body after the body is created in matter js?
I have added a body called testObj to the world like this
const testObj = Bodies.rectangle(200,200,40,40,)
World.add(engine.current.world, [
Bodies.rectangle(cw/2, 0, cw, 20, { isStatic: true }),
Bodies.rectangle(cw/2, ch, cw, 20, { isStatic: true }),
Bodies.rectangle(0, ch/2 , 20, ch, { isStatic: true }),
Bodies.rectangle(cw, ch/2 , 20, ch, { isStatic: true }),
testObj,])
and I have a button like this
<Button onClick={changeTexture}>change</Button>
so when I click this button I want to change the texture of testObj to a image.
( p.s- I am building this website with React if that matters. I'm using useEffect hook to render stuff.)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
