mirror of
https://github.com/liabru/matter-js.git
synced 2025-01-12 16:08:50 -05:00
improved Demo.manipulation
This commit is contained in:
parent
0a453a2b63
commit
e186ccd7e2
1 changed files with 12 additions and 4 deletions
|
@ -244,9 +244,10 @@
|
||||||
bodyC = Bodies.rectangle(300, 200, 50, 50),
|
bodyC = Bodies.rectangle(300, 200, 50, 50),
|
||||||
bodyD = Bodies.rectangle(400, 200, 50, 50),
|
bodyD = Bodies.rectangle(400, 200, 50, 50),
|
||||||
bodyE = Bodies.rectangle(550, 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,
|
var counter = 0,
|
||||||
scaleFactor = 1.01;
|
scaleFactor = 1.01;
|
||||||
|
@ -255,10 +256,13 @@
|
||||||
Events.on(_engine, 'tick', function(event) {
|
Events.on(_engine, 'tick', function(event) {
|
||||||
counter += 1;
|
counter += 1;
|
||||||
|
|
||||||
|
if (counter === 40)
|
||||||
|
Body.setStatic(bodyG, true);
|
||||||
|
|
||||||
if (scaleFactor > 1) {
|
if (scaleFactor > 1) {
|
||||||
Body.scale(bodyF, scaleFactor, scaleFactor);
|
Body.scale(bodyF, scaleFactor, scaleFactor);
|
||||||
|
|
||||||
// modify body vertices
|
// modify bodyE vertices
|
||||||
bodyE.vertices[0].x -= 0.2;
|
bodyE.vertices[0].x -= 0.2;
|
||||||
bodyE.vertices[0].y -= 0.2;
|
bodyE.vertices[0].y -= 0.2;
|
||||||
bodyE.vertices[1].x += 0.2;
|
bodyE.vertices[1].x += 0.2;
|
||||||
|
@ -266,9 +270,12 @@
|
||||||
Body.setVertices(bodyE, bodyE.vertices);
|
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
|
// every 1.5 sec
|
||||||
if (counter >= 60 * 1.5) {
|
if (counter >= 60 * 1.5) {
|
||||||
Body.setPosition(bodyA, { x: 100, y: 200 });
|
|
||||||
Body.setVelocity(bodyB, { x: 0, y: -10 });
|
Body.setVelocity(bodyB, { x: 0, y: -10 });
|
||||||
Body.setAngle(bodyC, -Math.PI * 0.26);
|
Body.setAngle(bodyC, -Math.PI * 0.26);
|
||||||
Body.setAngularVelocity(bodyD, 0.2);
|
Body.setAngularVelocity(bodyD, 0.2);
|
||||||
|
@ -281,6 +288,7 @@
|
||||||
);
|
);
|
||||||
|
|
||||||
var renderOptions = _engine.render.options;
|
var renderOptions = _engine.render.options;
|
||||||
|
renderOptions.wireframes = false;
|
||||||
renderOptions.showAxes = true;
|
renderOptions.showAxes = true;
|
||||||
renderOptions.showCollisions = true;
|
renderOptions.showCollisions = true;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue