public
Last active

bootstrapping my game

  • Download Gist
app.html
HTML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>sidera</title>
 
<link href="/css/default.css" rel="stylesheet" />
 
<script src="requestAnimationFrameShim.js"></script>
<script src="bootstrap.js"></script>
 
</head>
<body>
<canvas id="board"></canvas>
</body>
</html>
boostrap.js
JavaScript
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 32 33
var canvas, // the visible canvas element
surface, // the 2d context of `canvas`
currentScreen; // the currently rendered screen for the game
 
function beginLoop() {
var frameId = 0;
var lastFrame = Date.now();
 
function loop() {
var thisFrame = Date.now();
 
var elapsed = thisFrame - lastFrame;
 
frameId = window.requestAnimationFrame(loop);
 
currentScreen.update(elapsed);
currentScreen.draw(surface);
 
lastFrame = thisFrame;
}
 
loop();
}
 
 
canvas = document.querySelector('canvas#board');
canvas.setAttribute('width', 800);
canvas.setAttribute('height', 600);
 
surface = canvas.getContext('2d');
 
currentScreen = startScreen;
beginLoop();

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.