Created
January 2, 2014 08:07
-
-
Save sjkillen/8216262 to your computer and use it in GitHub Desktop.
Html5 Game Handy Framework
This file contains 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
loadJavascript('html_event_listeners.js'); | |
loadJavascript('main.js'); |
This file contains 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
htmlEvent=new Object(); | |
htmlEvent.windowResize=function() | |
{ | |
gwidth=window.innerWidth; | |
gheight=window.innerHeight; | |
canvas.element.width=gwidth; | |
canvas.element.height=gheight; | |
} | |
window.addEventListener('resize',htmlEvent.windowResize); | |
This file contains 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
<html> | |
<head> | |
<title>HTML5 GAME FRAMEWORK</title> | |
</head> | |
<body> | |
<style> | |
canvas | |
{ | |
position:absolute; | |
left:0; | |
top:0; | |
background:navy; | |
} | |
</style> | |
<canvas id="canvas"></canvas> | |
<script src="js_file_loader.js"></script> | |
<script src="file_init.js"></script> | |
</body> | |
</html> |
This file contains 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
function loadJavascript(path) | |
{ | |
if (typeof (path)==='string') | |
{ | |
var element=document.createElement("script"); | |
element.src=path; | |
document.body.appendChild(element); | |
} | |
else {error('Cannot load Javascript, path is not a string');} | |
} |
This file contains 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
canvas= | |
{ | |
element:document.getElementById('canvas'), | |
context:document.getElementById('canvas').getContext('2d') | |
}; | |
fps= | |
{ | |
draw:1000/60, | |
think:1000/60 | |
}; | |
game=new Object(); | |
game.vSync=true; | |
game.looping=false; | |
htmlEvent.windowResize(); | |
game.thinkLoop=function() | |
{ | |
}; | |
game.drawLoop=function() | |
{ | |
}; | |
game.startLoops=function() | |
{ | |
if (!game.looping) | |
{ | |
game.thinkLoopSession=setInterval(game.thinkLoop,fps.think); | |
if (game.vSync) {game.drawLoopSession=requestAnimationFrame(game.drawLoop);} | |
else {game.drawLoopSession=setInterval(game.drawLoop,fps.draw);} | |
game.looping=true; | |
} | |
else{error('Game is already looping');} | |
} | |
game.haltLoops=function() | |
{ | |
if (game.looping) | |
{ | |
if (game.vSync) {window.cancelAnimationFrame(game.drawLoopSession);} | |
else {clearInterval(game.drawLoopSession);} | |
clearInterval(game.thinkLoopSession); | |
game.looping=false; | |
} | |
else{error('Game is not looping');} | |
} | |
function error(err) | |
{ | |
if (typeof (err)=="string") {console.log('ERROR: '+err);} | |
else {console.log('ERROR REASON NOT GIVEN');} | |
game.haltLoops(); | |
alert('Game has crashed, please restart'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment