mirror of
https://github.com/liabru/matter-js.git
synced 2024-11-23 09:26:51 -05:00
added lastDelta and lastElapsed to engine.timing
This commit is contained in:
parent
081645474c
commit
6dc703f9a9
1 changed files with 9 additions and 1 deletions
|
@ -54,7 +54,9 @@ var Body = require('../body/Body');
|
|||
plugin: {},
|
||||
timing: {
|
||||
timestamp: 0,
|
||||
timeScale: 1
|
||||
timeScale: 1,
|
||||
lastDelta: 0,
|
||||
lastElapsed: 0
|
||||
},
|
||||
broadphase: {
|
||||
controller: Grid
|
||||
|
@ -111,6 +113,8 @@ var Body = require('../body/Body');
|
|||
* @param {number} [correction=1]
|
||||
*/
|
||||
Engine.update = function(engine, delta, correction) {
|
||||
var startTime = Common.now();
|
||||
|
||||
delta = delta || 1000 / 60;
|
||||
correction = correction || 1;
|
||||
|
||||
|
@ -122,6 +126,7 @@ var Body = require('../body/Body');
|
|||
|
||||
// increment timestamp
|
||||
timing.timestamp += delta * timing.timeScale;
|
||||
timing.lastDelta = delta * timing.timeScale;
|
||||
|
||||
// create an event object
|
||||
var event = {
|
||||
|
@ -229,6 +234,9 @@ var Body = require('../body/Body');
|
|||
|
||||
Events.trigger(engine, 'afterUpdate', event);
|
||||
|
||||
// log the time elapsed computing this update
|
||||
engine.timing.lastElapsed = Common.now() - startTime;
|
||||
|
||||
return engine;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue