-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.js
38 lines (29 loc) · 842 Bytes
/
Main.js
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
34
35
36
37
38
// Canvas & context
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
var minimumResize = 1;
// Controls
var controls = {};
var layer;
var gameLayer;
function startGame() {
gameLayer = new GameLayer();
layer=gameLayer;
setInterval(loop, 1000 / 30);
}
function loop(){
layer.update();
layer.processControls();
layer.draw();
}
// Resize
window.addEventListener('load', resize, false);
function resize() {
console.log("Resize")
var resizeWidth = parseFloat(window.innerWidth / canvas.width);
var resizeHeight = parseFloat(window.innerHeight / canvas.height);
minimumResize = Math.min(resizeWidth, resizeHeight);
canvas.width = canvas.width*minimumResize;
canvas.height = canvas.height*minimumResize;
context.scale(minimumResize, minimumResize);
}