Update index.html

Fix problems arising from the new webkit implementation of window.performace.now (high resolution timer draft).
This commit is contained in:
arcadeJHS 2013-02-11 19:24:24 +01:00
parent 36f27c2da3
commit f595895a32

View File

@ -318,23 +318,32 @@
return el.querySelector(selector); return el.querySelector(selector);
}; };
// crossbrowser implementation for requestAnimationFrame
/*var requestAnimation = (function() {
return window.requestAnimationFrame
|| window.webkitRequestAnimationFrame
|| window.mozRequestAnimationFrame
|| window.oRequestAnimationFrame
|| window.msRequestAnimationFrame
|| function(callback, element) {
window.setTimeout(callback, 1000/60);
};
})();*/
var requestAnimation = (function() { (function() {
return function(callback, element) { var lastTime = 0;
window.setTimeout(callback, 1000/60); var vendors = ['ms', 'moz', 'webkit', 'o'];
}; for(var x = 0; x < vendors.length && !window.requestAnimationFrameFrame; ++x) {
})(); window.requestAnimationFrameFrame = window[vendors[x]+'requestAnimationFrameFrame'];
window.cancelAnimationFrame =
window[vendors[x]+'CancelAnimationFrame'] || window[vendors[x]+'CancelrequestAnimationFrameFrame'];
}
if (!window.requestAnimationFrameFrame)
window.requestAnimationFrameFrame = function(callback, element) {
var currTime = new Date().getTime();
var timeToCall = Math.max(0, 16 - (currTime - lastTime));
var id = window.setTimeout(function() { callback(currTime + timeToCall); },
timeToCall);
lastTime = currTime + timeToCall;
return id;
};
if (!window.cancelAnimationFrame)
window.cancelAnimationFrame = function(id) {
clearTimeout(id);
};
}());
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// game objects // game objects
@ -1314,8 +1323,9 @@
// animation loop // animation loop
var gameWrapper = $("#game"); var gameWrapper = $("#game");
var startTime = window.mozAnimationStartTime || +new Date; var startTime = window.performance.now() || window.mozAnimationStartTime || +new Date;
requestAnimation(loop, gameWrapper);
requestAnimationFrame(loop, gameWrapper);
function loop(timestamp) { function loop(timestamp) {
// time since last draw // time since last draw
var drawStart = (timestamp || +new Date); var drawStart = (timestamp || +new Date);
@ -1331,7 +1341,7 @@
startTime = drawStart; startTime = drawStart;
} }
requestAnimation(loop, gameWrapper); requestAnimationFrame(loop, gameWrapper);
} }
} }
@ -1453,9 +1463,11 @@
// animation loop // animation loop
var gameWrapper = $("#game"); var gameWrapper = $("#game");
var startTime = window.mozAnimationStartTime || +new Date; debugger;
requestAnimation(loop, gameWrapper); var startTime = window.performance.now() || window.mozAnimationStartTime || +new Date;
requestAnimationFrame(loop, gameWrapper);
function loop(timestamp) { function loop(timestamp) {
// time since last draw // time since last draw
var drawStart = (timestamp || +new Date); var drawStart = (timestamp || +new Date);
var diff = drawStart - startTime; var diff = drawStart - startTime;
@ -1473,7 +1485,7 @@
startTime = drawStart; startTime = drawStart;
} }
requestAnimation(loop, gameWrapper); requestAnimationFrame(loop, gameWrapper);
} }
}; };