BlueGit

timfa frameworkv3

Binding 'this' to update to keep reference through global scope

timfa wsadhelios · pushed by timfa

Authored 2022-10-15 · 4 years ago

Hash
9ffcd9db317a607684bcc76ecd5157e52665f165
Parent
ab89bf24
1 file changed +8 −0
framework/engine/game.js +8 −0
@@ -7,6 +7,11 @@ class Game
7 7 {
8 8 this.previousStep = 0;
9 9 this.activeScenes = [];
10 this.update = this.update.bind(this);
11 }
12
13 startGame() {
14 this.update();
10 15 }
11 16
12 17 loadScene(scene)
@@ -17,6 +22,7 @@ class Game
17 22
18 23 update()
19 24 {
25 console.log("update");
20 26 this.previousStep = this.previousStep || 0;
21 27 let stepTime = Date.now();
22 28 let stepTimeCurr = (stepTime - this.previousStep) * 0.001;
@@ -31,5 +37,7 @@ class Game
31 37 }
32 38
33 39 this.previousStep = stepTime;
40
41 requestAnimationFrame(this.update);
34 42 }
35 43 }
@@ -7,6 +7,11 @@ class Game
7 {
7 {
8 this.previousStep = 0;
8 this.previousStep = 0;
9 this.activeScenes = [];
9 this.activeScenes = [];
10 this.update = this.update.bind(this);
11 }
12
13 startGame() {
14 this.update();
10 }
15 }
11
16
12 loadScene(scene)
17 loadScene(scene)
@@ -17,6 +22,7 @@ class Game
17
22
18 update()
23 update()
19 {
24 {
25 console.log("update");
20 this.previousStep = this.previousStep || 0;
26 this.previousStep = this.previousStep || 0;
21 let stepTime = Date.now();
27 let stepTime = Date.now();
22 let stepTimeCurr = (stepTime - this.previousStep) * 0.001;
28 let stepTimeCurr = (stepTime - this.previousStep) * 0.001;
@@ -31,5 +37,7 @@ class Game
31 }
37 }
32
38
33 this.previousStep = stepTime;
39 this.previousStep = stepTime;
40
41 requestAnimationFrame(this.update);
34 }
42 }
35}
43}