mirror of
https://github.com/liabru/matter-js.git
synced 2025-01-21 17:14:38 -05:00
update Example.staticFriction and Example.timeScale
This commit is contained in:
parent
5ddac71316
commit
11d5e73c1f
2 changed files with 8 additions and 4 deletions
|
@ -62,6 +62,11 @@ Example.staticFriction = function() {
|
||||||
|
|
||||||
var px = 400 + 100 * Math.sin((engine.timing.timestamp - 1500) * 0.001);
|
var px = 400 + 100 * Math.sin((engine.timing.timestamp - 1500) * 0.001);
|
||||||
|
|
||||||
|
// manual update velocity required for older releases
|
||||||
|
if (Matter.version === '0.18.0') {
|
||||||
|
Body.setVelocity(body, { x: px - body.position.x, y: 0 });
|
||||||
|
}
|
||||||
|
|
||||||
Body.setPosition(body, { x: px, y: body.position.y }, true);
|
Body.setPosition(body, { x: px, y: body.position.y }, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -42,15 +42,14 @@ Example.timescale = function() {
|
||||||
Bodies.rectangle(0, 300, 50, 600, { isStatic: true })
|
Bodies.rectangle(0, 300, 50, 600, { isStatic: true })
|
||||||
]);
|
]);
|
||||||
|
|
||||||
var explosion = function(engine, delta) {
|
var explosion = function(engine) {
|
||||||
var timeScale = delta / 1000;
|
|
||||||
var bodies = Composite.allBodies(engine.world);
|
var bodies = Composite.allBodies(engine.world);
|
||||||
|
|
||||||
for (var i = 0; i < bodies.length; i++) {
|
for (var i = 0; i < bodies.length; i++) {
|
||||||
var body = bodies[i];
|
var body = bodies[i];
|
||||||
|
|
||||||
if (!body.isStatic && body.position.y >= 500) {
|
if (!body.isStatic && body.position.y >= 500) {
|
||||||
// Scale force accounting for time delta.
|
// Scale force accounting for mass
|
||||||
var forceMagnitude = (0.05 * body.mass);
|
var forceMagnitude = (0.05 * body.mass);
|
||||||
|
|
||||||
Body.applyForce(body, body.position, {
|
Body.applyForce(body, body.position, {
|
||||||
|
@ -65,7 +64,7 @@ Example.timescale = function() {
|
||||||
lastTime = Common.now();
|
lastTime = Common.now();
|
||||||
|
|
||||||
Events.on(engine, 'afterUpdate', function(event) {
|
Events.on(engine, 'afterUpdate', function(event) {
|
||||||
var timeScale = timeScale = (event.delta || (1000 / 60)) / 1000;
|
var timeScale = (event.delta || (1000 / 60)) / 1000;
|
||||||
|
|
||||||
// tween the timescale for bullet time slow-mo
|
// tween the timescale for bullet time slow-mo
|
||||||
engine.timing.timeScale += (timeScaleTarget - engine.timing.timeScale) * 12 * timeScale;
|
engine.timing.timeScale += (timeScaleTarget - engine.timing.timeScale) * 12 * timeScale;
|
||||||
|
|
Loading…
Add table
Reference in a new issue