BlueGit

timfa frameworkv3

primary scene flag

timfa Tim · pushed by timfa

Authored 2022-10-18 · 4 years ago

Hash
33c5def39e7b6accba21f429f0f27573adefbff3
Parent
c0259bef
2 files changed +26 −0
framework/engine/game.js +14 −0
@@ -31,6 +31,17 @@ class Game
31 31 cont.apply();
32 32 }
33 33
34 setPrimaryScene(scene)
35 {
36 if(this.activeScenes.contains(scene))
37 {
38 for(let i = 0; i < this.activeScenes.length; i++)
39 this.activeScenes[i].g_primary = false;
40
41 scene.g_primary = true;
42 }
43 }
44
34 45 async preloadImages(imagesData) {
35 46 const promises = [];
36 47 const context = this;
@@ -67,6 +78,9 @@ class Game
67 78
68 79 loadScene(scene)
69 80 {
81 if(this.activeScenes.length == 0)
82 scene.g_primary = true;
83
70 84 this.activeScenes.push(scene);
71 85 scene.game = this;
72 86 scene.onLoad();
@@ -31,6 +31,17 @@ class Game
31 cont.apply();
31 cont.apply();
32 }
32 }
33
33
34 setPrimaryScene(scene)
35 {
36 if(this.activeScenes.contains(scene))
37 {
38 for(let i = 0; i < this.activeScenes.length; i++)
39 this.activeScenes[i].g_primary = false;
40
41 scene.g_primary = true;
42 }
43 }
44
34 async preloadImages(imagesData) {
45 async preloadImages(imagesData) {
35 const promises = [];
46 const promises = [];
36 const context = this;
47 const context = this;
@@ -67,6 +78,9 @@ class Game
67
78
68 loadScene(scene)
79 loadScene(scene)
69 {
80 {
81 if(this.activeScenes.length == 0)
82 scene.g_primary = true;
83
70 this.activeScenes.push(scene);
84 this.activeScenes.push(scene);
71 scene.game = this;
85 scene.game = this;
72 scene.onLoad();
86 scene.onLoad();
framework/engine/scene.js +12 −0
@@ -10,6 +10,8 @@ class Scene
10 10 cameraPosition = null;
11 11 parentScene = null;
12 12
13 g_primary = false;
14
13 15 static DisplayModes = {absolute: 0, relativeToParent: 1}
14 16
15 17 displayMode = Scene.DisplayModes.absolute;
@@ -20,6 +22,11 @@ class Scene
20 22
21 23 game = null;
22 24
25 get primary()
26 {
27 return this.g_primary;
28 }
29
23 30 constructor(x, y, width, height, displayMode = 0)
24 31 {
25 32 Scene.idCount++;
@@ -40,6 +47,11 @@ class Scene
40 47 this.cv_context = this.cv_canvas.getContext('2d');
41 48 }
42 49
50 setPrimary()
51 {
52 this.game.setPrimaryScene(this);
53 }
54
43 55 onLoad()
44 56 {
45 57
@@ -10,6 +10,8 @@ class Scene
10 cameraPosition = null;
10 cameraPosition = null;
11 parentScene = null;
11 parentScene = null;
12
12
13 g_primary = false;
14
13 static DisplayModes = {absolute: 0, relativeToParent: 1}
15 static DisplayModes = {absolute: 0, relativeToParent: 1}
14
16
15 displayMode = Scene.DisplayModes.absolute;
17 displayMode = Scene.DisplayModes.absolute;
@@ -20,6 +22,11 @@ class Scene
20
22
21 game = null;
23 game = null;
22
24
25 get primary()
26 {
27 return this.g_primary;
28 }
29
23 constructor(x, y, width, height, displayMode = 0)
30 constructor(x, y, width, height, displayMode = 0)
24 {
31 {
25 Scene.idCount++;
32 Scene.idCount++;
@@ -40,6 +47,11 @@ class Scene
40 this.cv_context = this.cv_canvas.getContext('2d');
47 this.cv_context = this.cv_canvas.getContext('2d');
41 }
48 }
42
49
50 setPrimary()
51 {
52 this.game.setPrimaryScene(this);
53 }
54
43 onLoad()
55 onLoad()
44 {
56 {
45
57