mirror of
https://github.com/liabru/matter-js.git
synced 2024-11-27 09:50:52 -05:00
fix requestAnimationFrame polyfill for Matter.Runner, closes #252
This commit is contained in:
parent
34524651fb
commit
7c8f6ced5c
1 changed files with 15 additions and 2 deletions
|
@ -25,13 +25,26 @@ var Common = require('./Common');
|
||||||
|
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
_requestAnimationFrame = window.requestAnimationFrame || window.webkitRequestAnimationFrame
|
_requestAnimationFrame = window.requestAnimationFrame || window.webkitRequestAnimationFrame
|
||||||
|| window.mozRequestAnimationFrame || window.msRequestAnimationFrame
|
|| window.mozRequestAnimationFrame || window.msRequestAnimationFrame;
|
||||||
|| function(callback){ window.setTimeout(function() { callback(Common.now()); }, 1000 / 60); };
|
|
||||||
|
|
||||||
_cancelAnimationFrame = window.cancelAnimationFrame || window.mozCancelAnimationFrame
|
_cancelAnimationFrame = window.cancelAnimationFrame || window.mozCancelAnimationFrame
|
||||||
|| window.webkitCancelAnimationFrame || window.msCancelAnimationFrame;
|
|| window.webkitCancelAnimationFrame || window.msCancelAnimationFrame;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!_requestAnimationFrame) {
|
||||||
|
var _frameTimeout;
|
||||||
|
|
||||||
|
_requestAnimationFrame = function(callback){
|
||||||
|
_frameTimeout = setTimeout(function() {
|
||||||
|
callback(Common.now());
|
||||||
|
}, 1000 / 60);
|
||||||
|
};
|
||||||
|
|
||||||
|
_cancelAnimationFrame = function() {
|
||||||
|
clearTimeout(_frameTimeout);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new Runner. The options parameter is an object that specifies any properties you wish to override the defaults.
|
* Creates a new Runner. The options parameter is an object that specifies any properties you wish to override the defaults.
|
||||||
* @method create
|
* @method create
|
||||||
|
|
Loading…
Reference in a new issue