-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
31 lines (28 loc) · 812 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* requestAnim shim layer by Paul Irish
* Finds the first API that works to optimize the animation loop,
* otherwise defaults to setTimeout().
*/
window.requestAnimFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(/* function */ callback, /* DOMElement */ element){
window.setTimeout(callback, 1000 / 60);
};
})();
var game = new Game();
var lastTick = Date.now();
function animate() {
while (Date.now() - lastTick >= 250) {
game.update();
lastTick += 250; //Date.now();
}
game.draw();
requestAnimFrame( animate );
};
function init() {
if(game.init()) game.start();
}