mirror of
https://github.com/liabru/matter-js.git
synced 2025-01-12 16:08: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,
|
||||
deltaMin: 1000 / _fps,
|
||||
deltaMax: 1000 / (_fps * 0.5),
|
||||
timeScale: 1
|
||||
timeScale: 1,
|
||||
isFixed: false
|
||||
},
|
||||
render: {
|
||||
element: element,
|
||||
|
@ -87,7 +88,7 @@ var Engine = {};
|
|||
Engine.run = function(engine) {
|
||||
var timing = engine.timing,
|
||||
delta,
|
||||
correction,
|
||||
correction = 1,
|
||||
counterTimestamp = 0,
|
||||
frameCounter = 0,
|
||||
deltaHistory = [],
|
||||
|
@ -109,6 +110,11 @@ var Engine = {};
|
|||
|
||||
Events.trigger(engine, 'beforeTick', event);
|
||||
|
||||
if (timing.isFixed) {
|
||||
// fixed timestep
|
||||
delta = timing.delta;
|
||||
} else {
|
||||
// dynamic timestep
|
||||
delta = (timestamp - timing.timestamp) || _delta;
|
||||
|
||||
// optimistically filter delta over a few frames, to improve stability
|
||||
|
@ -122,6 +128,7 @@ var Engine = {};
|
|||
|
||||
// time correction for delta
|
||||
correction = delta / timing.delta;
|
||||
}
|
||||
|
||||
// time correction for time scaling
|
||||
if (timeScalePrev !== 0)
|
||||
|
|
Loading…
Reference in a new issue