mirror of
https://github.com/liabru/matter-js.git
synced 2024-11-23 09:26:51 -05:00
added Demo.staticFriction
This commit is contained in:
parent
de4784c492
commit
4491dfd5f4
2 changed files with 45 additions and 4 deletions
|
@ -67,6 +67,7 @@
|
|||
<option value="restitution">Restitution</option>
|
||||
<option value="friction">Friction</option>
|
||||
<option value="airFriction">Air Friction</option>
|
||||
<option value="staticFriction">Static Friction</option>
|
||||
<option value="sleeping">Sleeping</option>
|
||||
<option value="broadphase">Grid Broadphase</option>
|
||||
<option value="beachBalls">Beach Balls</option>
|
||||
|
|
|
@ -775,8 +775,8 @@
|
|||
]);
|
||||
|
||||
var renderOptions = _engine.render.options;
|
||||
renderOptions.showAngleIndicator = true;
|
||||
renderOptions.showCollisions = true;
|
||||
renderOptions.showAngleIndicator = false;
|
||||
renderOptions.showVelocity = true;
|
||||
};
|
||||
|
||||
Demo.airFriction = function() {
|
||||
|
@ -791,8 +791,48 @@
|
|||
]);
|
||||
|
||||
var renderOptions = _engine.render.options;
|
||||
renderOptions.showAngleIndicator = true;
|
||||
renderOptions.showCollisions = true;
|
||||
renderOptions.showAngleIndicator = false;
|
||||
renderOptions.showVelocity = true;
|
||||
};
|
||||
|
||||
Demo.staticFriction = function() {
|
||||
var _world = _engine.world;
|
||||
|
||||
Demo.reset();
|
||||
|
||||
var body = Bodies.rectangle(400, 500, 200, 60, { isStatic: true, chamfer: 10 }),
|
||||
size = 50,
|
||||
counter = -1;
|
||||
|
||||
var stack = Composites.stack(350, 470 - 6 * size, 1, 6, 0, 0, function(x, y, column, row) {
|
||||
return Bodies.rectangle(x, y, size * 2, size, {
|
||||
slop: 0.5,
|
||||
friction: 1,
|
||||
frictionStatic: Infinity
|
||||
});
|
||||
});
|
||||
|
||||
World.add(_world, [body, stack]);
|
||||
|
||||
_sceneEvents.push(
|
||||
Events.on(_engine, 'beforeUpdate', function(event) {
|
||||
counter += 0.014;
|
||||
|
||||
if (counter < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
var px = 400 + 100 * Math.sin(counter);
|
||||
|
||||
// body is static so must manually update velocity for friction to work
|
||||
Body.setVelocity(body, { x: px - body.position.x, y: 0 });
|
||||
Body.setPosition(body, { x: px, y: body.position.y });
|
||||
})
|
||||
);
|
||||
|
||||
var renderOptions = _engine.render.options;
|
||||
renderOptions.showAngleIndicator = false;
|
||||
renderOptions.showVelocity = true;
|
||||
};
|
||||
|
||||
Demo.sleeping = function() {
|
||||
|
|
Loading…
Reference in a new issue