BlueGit

timfa frameworkv3

move primary back to a parent, sorting draw prio to copy (conflicted with removal)

timfa wsadhelios · pushed by timfa

Authored 2022-10-22 · 4 years ago

Hash
80eca2ac6379c2d4d66fac53a1062d5b8cac361b
Parent
4281139f
2 files changed +10 −6
framework/engine/game.js +1 −2
@@ -50,7 +50,6 @@ class Game
50 50 {
51 51 const promises = [];
52 52 const context = this;
53 console.log(imagesData);
54 53
55 54 for (var imageData of imagesData)
56 55 {
@@ -81,7 +80,7 @@ class Game
81 80 }
82 81 await Promise.all(promises);
83 82
84 console.log("all images loaded");
83 console.log("all images loaded ", this.images);
85 84
86 85 return this.images;
87 86 }
@@ -50,7 +50,6 @@ class Game
50 {
50 {
51 const promises = [];
51 const promises = [];
52 const context = this;
52 const context = this;
53 console.log(imagesData);
54
53
55 for (var imageData of imagesData)
54 for (var imageData of imagesData)
56 {
55 {
@@ -81,7 +80,7 @@ class Game
81 }
80 }
82 await Promise.all(promises);
81 await Promise.all(promises);
83
82
84 console.log("all images loaded");
83 console.log("all images loaded ", this.images);
85
84
86 return this.images;
85 return this.images;
87 }
86 }
framework/engine/scene.js +9 −4
@@ -81,6 +81,11 @@ class Scene
81 81
82 82 this.removeCanvas();
83 83
84 if (this.primary && this.parentScene)
85 {
86 this.parentScene.setPrimary();
87 }
88
84 89 this.destroyed = true;
85 90 }
86 91 }
@@ -213,12 +218,12 @@ class Scene
213 218 this.context.clearRect(0, 0, this.real_size.x, this.real_size.y);
214 219 }
215 220
216 this.activeObjects.sort((a, b) => a.layer - b.layer);
221 let sortedActiveObjects = this.activeObjects.slice().sort((a, b) => a.layer - b.layer);
217 222
218 for (var i = 0; i < this.activeObjects.length; i++)
223 for (var i = 0; i < sortedActiveObjects.length; i++)
219 224 {
220 if (!this.activeObjects[i].destroyed && this.activeObjects[i].renderer.visible)
221 this.activeObjects[i].draw(this.context);
225 if (!sortedActiveObjects[i].destroyed && sortedActiveObjects[i].renderer.visible)
226 sortedActiveObjects[i].draw(this.context);
222 227 }
223 228 }
224 229 }
@@ -81,6 +81,11 @@ class Scene
81
81
82 this.removeCanvas();
82 this.removeCanvas();
83
83
84 if (this.primary && this.parentScene)
85 {
86 this.parentScene.setPrimary();
87 }
88
84 this.destroyed = true;
89 this.destroyed = true;
85 }
90 }
86 }
91 }
@@ -213,12 +218,12 @@ class Scene
213 this.context.clearRect(0, 0, this.real_size.x, this.real_size.y);
218 this.context.clearRect(0, 0, this.real_size.x, this.real_size.y);
214 }
219 }
215
220
216 this.activeObjects.sort((a, b) => a.layer - b.layer);
221 let sortedActiveObjects = this.activeObjects.slice().sort((a, b) => a.layer - b.layer);
217
222
218 for (var i = 0; i < this.activeObjects.length; i++)
223 for (var i = 0; i < sortedActiveObjects.length; i++)
219 {
224 {
220 if (!this.activeObjects[i].destroyed && this.activeObjects[i].renderer.visible)
225 if (!sortedActiveObjects[i].destroyed && sortedActiveObjects[i].renderer.visible)
221 this.activeObjects[i].draw(this.context);
226 sortedActiveObjects[i].draw(this.context);
222 }
227 }
223 }
228 }
224}
229}