3

I have a small example script, where I have a circle (radius:40), which falls down to the ground. But when I increase its radius to 80 then, only the graphics of the circle seem to change, but not the physics:

<html>
<body></body>
</html>
<script src="matter.js"></script>
<script>
var Engine = Matter.Engine,
    World = Matter.World,
    Bodies = Matter.Bodies
engine = Engine.create(document.body,{render:{options:{wireframes: false}}})
engine.render.options.background = "#7f7f7f"
ground = Bodies.rectangle(400,590,800,20,{isStatic:true})
World.add(engine.world, ground)
circle = Bodies.circle(400,20,40,{render:{fillStyle:"#0000ff"}})
World.add(engine.world, circle)
Engine.run(engine)
setTimeout(increaseRadius, 1500)

function increaseRadius(){
  circle.circleRadius = 80
}
</script>

enter image description here

4

1 回答 1

2

我的猜测是,通过您的方法,您还必须再次调用 World.add(engine.world, circle) 并可能删除半径较小的前一个圆,因为引擎使用圆的副本。或者,您可以在正文上调用 scale 方法:http: //brm.io/matter-js-docs/classes/Body.html#method_scale

于 2015-09-20T18:10:43.837 回答