mirror of
https://github.com/liabru/matter-js.git
synced 2025-01-13 16:18:50 -05:00
added engine.timing.isFixed option
This commit is contained in:
parent
a77a5fc626
commit
bc35c93106
1 changed files with 20 additions and 13 deletions
|
@ -48,7 +48,8 @@ var Engine = {};
|
||||||
correction: 1,
|
correction: 1,
|
||||||
deltaMin: 1000 / _fps,
|
deltaMin: 1000 / _fps,
|
||||||
deltaMax: 1000 / (_fps * 0.5),
|
deltaMax: 1000 / (_fps * 0.5),
|
||||||
timeScale: 1
|
timeScale: 1,
|
||||||
|
isFixed: false
|
||||||
},
|
},
|
||||||
render: {
|
render: {
|
||||||
element: element,
|
element: element,
|
||||||
|
@ -87,7 +88,7 @@ var Engine = {};
|
||||||
Engine.run = function(engine) {
|
Engine.run = function(engine) {
|
||||||
var timing = engine.timing,
|
var timing = engine.timing,
|
||||||
delta,
|
delta,
|
||||||
correction,
|
correction = 1,
|
||||||
counterTimestamp = 0,
|
counterTimestamp = 0,
|
||||||
frameCounter = 0,
|
frameCounter = 0,
|
||||||
deltaHistory = [],
|
deltaHistory = [],
|
||||||
|
@ -109,6 +110,11 @@ var Engine = {};
|
||||||
|
|
||||||
Events.trigger(engine, 'beforeTick', event);
|
Events.trigger(engine, 'beforeTick', event);
|
||||||
|
|
||||||
|
if (timing.isFixed) {
|
||||||
|
// fixed timestep
|
||||||
|
delta = timing.delta;
|
||||||
|
} else {
|
||||||
|
// dynamic timestep
|
||||||
delta = (timestamp - timing.timestamp) || _delta;
|
delta = (timestamp - timing.timestamp) || _delta;
|
||||||
|
|
||||||
// optimistically filter delta over a few frames, to improve stability
|
// optimistically filter delta over a few frames, to improve stability
|
||||||
|
@ -122,6 +128,7 @@ var Engine = {};
|
||||||
|
|
||||||
// time correction for delta
|
// time correction for delta
|
||||||
correction = delta / timing.delta;
|
correction = delta / timing.delta;
|
||||||
|
}
|
||||||
|
|
||||||
// time correction for time scaling
|
// time correction for time scaling
|
||||||
if (timeScalePrev !== 0)
|
if (timeScalePrev !== 0)
|
||||||
|
|
Loading…
Reference in a new issue