Skip to content

Commit

Permalink
added Demo.manipulation
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Jun 3, 2014
1 parent 7ed28f7 commit 0a453a2
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions demo/dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ <h1>Matter.js Demo (Dev. Build)</h1>
<option value="rounded">Rounded Corners (Chamfering)</option>
<option value="views">Views</option>
<option value="timescale">Time Scaling</option>
<option value="manipulation">Body Manipulation</option>
<option value="sprites">Sprites</option>
<option value="pyramid">Pyramid</option>
<option value="raycasting">Raycasting</option>
Expand Down
51 changes: 51 additions & 0 deletions demo/js/Demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,57 @@
renderOptions.showCollisions = true;
};

Demo.manipulation = function() {
var _world = _engine.world;

Demo.reset();

var bodyA = Bodies.rectangle(100, 200, 50, 50),
bodyB = Bodies.rectangle(200, 200, 50, 50),
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);

World.add(_world, [bodyA, bodyB, bodyC, bodyD, bodyE, bodyF]);

var counter = 0,
scaleFactor = 1.01;

_sceneEvents.push(
Events.on(_engine, 'tick', function(event) {
counter += 1;

if (scaleFactor > 1) {
Body.scale(bodyF, scaleFactor, scaleFactor);

// modify body 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);
}

// 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);

// reset counter
counter = 0;
scaleFactor = 1;
}
})
);

var renderOptions = _engine.render.options;
renderOptions.showAxes = true;
renderOptions.showCollisions = true;
};

Demo.views = function() {
var _world = _engine.world;

Expand Down

0 comments on commit 0a453a2

Please sign in to comment.