FrozenJS basic game loop
Simple example of using FrozeJS's GameCore to setup a simple game loop.
HTML
<script src="http://rawgithub.com/iceddev/frozen/master/dist/frozen.js.uncompressed.js"></script>
<div id="gameArea">
<canvas id="canvas" width="300" height="400" ></canvas>
</div>
CSS
body {
background-color: #222;
color: #fff;
}
#gameArea {
margin: 0 auto;
}
JavaScript
require(['frozen/GameCore'], function(GameCore){
var x = 0;
var y = 0;
var game = new GameCore({
canvasId: 'canvas',
gameAreaId: 'gameArea',
canvasPercentage: 1, //strech out 100% but keep canvas aspect ratio
update: function(millis){
//60 pixels per second regardles of computer speed.
x += millis / 16;
y += millis / 16;
},
draw: function(ctx){
ctx.fillRect(0,0, this.width, this.height);
ctx.fillStyle = 'white';
ctx.fillRect(x,y, 50,50);
}
});
game.run();
});