0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-12-26 13:49:01 -05:00

fixed Common.now

This commit is contained in:
liabru 2017-05-09 00:39:35 +01:00
parent 26c1200387
commit 2b76c4c10b

View file

@ -12,6 +12,7 @@ module.exports = Common;
Common._nextId = 0;
Common._seed = 0;
Common._nowStartTime = +(new Date());
/**
* Extends the object in the first argument using the object in the second argument.
@ -273,26 +274,21 @@ module.exports = Common;
};
/**
* Returns the current timestamp (high-res if available).
* Returns the current timestamp since the time origin (e.g. from page load).
* The result will be high-resolution including decimal places if available.
* @method now
* @return {number} the current timestamp (high-res if available)
* @return {number} the current timestamp
*/
Common.now = function() {
// http://stackoverflow.com/questions/221294/how-do-you-get-a-timestamp-in-javascript
// https://gist.github.com/davidwaterston/2982531
if (window.performance) {
if (window.performance.now) {
return window.performance.now();
} else if (window.performance.webkitNow) {
return window.performance.webkitNow();
}
}
var performance = window.performance || {};
performance.now = (function() {
return performance.now ||
performance.webkitNow ||
performance.msNow ||
performance.oNow ||
performance.mozNow ||
function() { return +(new Date()); };
})();
return performance.now();
return (new Date()) - Common._nowStartTime;
};
/**