-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
32 lines (27 loc) · 1016 Bytes
/
script.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
import StateManager from './src/stateManager.js'
// once all the HTML, CSS and other assets have loaded,
// we start with the JS init.
window.addEventListener("load", function() {
// get reference to the canvas object defined in the html page
const canvas = this.document.getElementById('canvas1');
const ctx = canvas.getContext("2d");
canvas.width = 600;
canvas.height = 800;
ctx.fillStyle = "white";
ctx.strokeStyle = "white";
ctx.lineWidth = 5;
ctx.font = "20px Impact";
const stateManager = new StateManager(canvas);
let lastTime = 0;
function animate(timestamp) {
const deltaTimeForAnimaton = timestamp - lastTime;
lastTime = timestamp;
// clear rect and paint the whole scene again
ctx.clearRect(0, 0, canvas.width, canvas.height)
stateManager.render(ctx, deltaTimeForAnimaton);
// recursively calls this function to re-draw the updated components
window.requestAnimationFrame(animate);
}
// start the recursive loop for animation
animate(0);
})