Skip to content

Commit

Permalink
improved Demo.manipulation
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Jun 4, 2014
1 parent 0a453a2 commit e186ccd
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions demo/js/Demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -255,20 +256,26 @@
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;
bodyE.vertices[1].y -= 0.2;
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);
Expand All @@ -281,6 +288,7 @@
);

var renderOptions = _engine.render.options;
renderOptions.wireframes = false;
renderOptions.showAxes = true;
renderOptions.showCollisions = true;
};
Expand Down

0 comments on commit e186ccd

Please sign in to comment.