Created
December 8, 2012 02:15
-
-
Save bennage/4238210 to your computer and use it in GitHub Desktop.
bootstrapping my game
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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