BlueGit

timfa frameworkv3

Files

frameworkv3 / framework / engine / game.js

game.js

big refactor
timfa Tim · pushed by timfa · 4 years ago
c94b8e9a History
game.js 695 B Download Raw
1class Game
2{
3 activeScenes = [];
4 previousStep = 0; //used for calculating deltaTime
5
6 constructor(initialScene)
7 {
8 this.activeScenes.push(initialScene);
9 this.update();
10 }
11
12 update()
13 {
14 let stepTime = Date.now();
15 let stepTimeCurr = (stepTime - this.previousStep) * 0.001;
16 stepTimeCurr = Math.min(stepTimeCurr, 0.1);
17 if(isNaN(stepTimeCurr))
18 stepTimeCurr = 0;
19
20 for(let i = 0; i < this.activeScenes.length; i++)
21 {
22 this.activeScenes[i].update(stepTimeCurr);
23 this.activeScenes[i].draw();
24 }
25
26 this.previousStep = stepTime;
27 requestAnimationFrame(this.update);
28 }
29}