From 7c8f6ced5cabf7e76bd0afabd34612e1d5529c65 Mon Sep 17 00:00:00 2001 From: liabru Date: Sun, 26 Jun 2016 20:38:06 +0100 Subject: [PATCH] fix requestAnimationFrame polyfill for Matter.Runner, closes #252 --- src/core/Runner.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/core/Runner.js b/src/core/Runner.js index efd3e3e5..21274beb 100644 --- a/src/core/Runner.js +++ b/src/core/Runner.js @@ -25,13 +25,26 @@ var Common = require('./Common'); if (typeof window !== 'undefined') { _requestAnimationFrame = window.requestAnimationFrame || window.webkitRequestAnimationFrame - || window.mozRequestAnimationFrame || window.msRequestAnimationFrame - || function(callback){ window.setTimeout(function() { callback(Common.now()); }, 1000 / 60); }; + || window.mozRequestAnimationFrame || window.msRequestAnimationFrame; _cancelAnimationFrame = window.cancelAnimationFrame || window.mozCancelAnimationFrame || 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. * @method create