Skip to content

Instantly share code, notes, and snippets.

@bennage
Created December 8, 2012 02:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bennage/4238210 to your computer and use it in GitHub Desktop.
Save bennage/4238210 to your computer and use it in GitHub Desktop.
bootstrapping my game
<!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>
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();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment