Skip to content

Commit 7c8f6ce

Browse files
committed
fix requestAnimationFrame polyfill for Matter.Runner, closes #252
1 parent 3452465 commit 7c8f6ce

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

src/core/Runner.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,26 @@ var Common = require('./Common');
2525

2626
if (typeof window !== 'undefined') {
2727
_requestAnimationFrame = window.requestAnimationFrame || window.webkitRequestAnimationFrame
28-
|| window.mozRequestAnimationFrame || window.msRequestAnimationFrame
29-
|| function(callback){ window.setTimeout(function() { callback(Common.now()); }, 1000 / 60); };
28+
|| window.mozRequestAnimationFrame || window.msRequestAnimationFrame;
3029

3130
_cancelAnimationFrame = window.cancelAnimationFrame || window.mozCancelAnimationFrame
3231
|| window.webkitCancelAnimationFrame || window.msCancelAnimationFrame;
3332
}
3433

34+
if (!_requestAnimationFrame) {
35+
var _frameTimeout;
36+
37+
_requestAnimationFrame = function(callback){
38+
_frameTimeout = setTimeout(function() {
39+
callback(Common.now());
40+
}, 1000 / 60);
41+
};
42+
43+
_cancelAnimationFrame = function() {
44+
clearTimeout(_frameTimeout);
45+
};
46+
}
47+
3548
/**
3649
* Creates a new Runner. The options parameter is an object that specifies any properties you wish to override the defaults.
3750
* @method create

0 commit comments

Comments
 (0)