From e186ccd7e20cb204b33a0b211fb45d3cbade44a1 Mon Sep 17 00:00:00 2001 From: liabru Date: Wed, 4 Jun 2014 15:41:17 +0100 Subject: [PATCH] improved Demo.manipulation --- demo/js/Demo.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/demo/js/Demo.js b/demo/js/Demo.js index a00d23e..e1ffdf3 100644 --- a/demo/js/Demo.js +++ b/demo/js/Demo.js @@ -244,9 +244,10 @@ bodyC = Bodies.rectangle(300, 200, 50, 50), bodyD = Bodies.rectangle(400, 200, 50, 50), bodyE = Bodies.rectangle(550, 200, 50, 50), - bodyF = Bodies.rectangle(700, 200, 50, 50); + bodyF = Bodies.rectangle(700, 200, 50, 50), + bodyG = Bodies.circle(400, 100, 25); - World.add(_world, [bodyA, bodyB, bodyC, bodyD, bodyE, bodyF]); + World.add(_world, [bodyA, bodyB, bodyC, bodyD, bodyE, bodyF, bodyG]); var counter = 0, scaleFactor = 1.01; @@ -255,10 +256,13 @@ Events.on(_engine, 'tick', function(event) { counter += 1; + if (counter === 40) + Body.setStatic(bodyG, true); + if (scaleFactor > 1) { Body.scale(bodyF, scaleFactor, scaleFactor); - // modify body vertices + // modify bodyE vertices bodyE.vertices[0].x -= 0.2; bodyE.vertices[0].y -= 0.2; bodyE.vertices[1].x += 0.2; @@ -266,9 +270,12 @@ Body.setVertices(bodyE, bodyE.vertices); } + // make bodyA move up and down and rotate constantly + Body.setPosition(bodyA, { x: 100, y: 300 + 100 * Math.sin(_engine.timing.timestamp * 0.005) }); + Body.setAngularVelocity(bodyA, 0.02); + // every 1.5 sec if (counter >= 60 * 1.5) { - Body.setPosition(bodyA, { x: 100, y: 200 }); Body.setVelocity(bodyB, { x: 0, y: -10 }); Body.setAngle(bodyC, -Math.PI * 0.26); Body.setAngularVelocity(bodyD, 0.2); @@ -281,6 +288,7 @@ ); var renderOptions = _engine.render.options; + renderOptions.wireframes = false; renderOptions.showAxes = true; renderOptions.showCollisions = true; };