BlueGit

timfa frameworkv3

poosh

timfa Tim · pushed by timfa

Authored 2022-10-20 · 4 years ago

Hash
d21347d72d46edf0b88a2400fa080e3b7569c3e6
Parent
68c624b6
2 files changed +7 −5
framework/engine/gameobject.js +1 −2
@@ -25,11 +25,10 @@ class GameObject
25 25 {
26 26 if (!this.destroyed)
27 27 {
28 this.destroyed = true;
29
30 28 this.onDestroy && this.onDestroy();
31 29
32 30 this.scene.removeObject(this);
31 this.destroyed = true;
33 32 }
34 33 }
35 34
@@ -25,11 +25,10 @@ class GameObject
25 {
25 {
26 if (!this.destroyed)
26 if (!this.destroyed)
27 {
27 {
28 this.destroyed = true;
29
30 this.onDestroy && this.onDestroy();
28 this.onDestroy && this.onDestroy();
31
29
32 this.scene.removeObject(this);
30 this.scene.removeObject(this);
31 this.destroyed = true;
33 }
32 }
34 }
33 }
35
34
framework/engine/scene.js +6 −3
@@ -109,9 +109,10 @@ class Scene
109 109 removeObject (obj)
110 110 {
111 111 let index = this.activeObjects.indexOf(obj);
112 if (index >= 0)
112 if (index >= 0 && !obj.destroyed)
113 113 {
114 this.pendingRemoval.push(index);
114 if (!this.pendingRemoval.contains(index))
115 this.pendingRemoval.push(index);
115 116 }
116 117 }
117 118
@@ -126,10 +127,12 @@ class Scene
126 127 {
127 128 this.pendingRemoval.sort();
128 129
129 for (let i = this.pendingRemoval.length; i >= 0; i++)
130 for (let i = this.pendingRemoval.length - 1; i >= 0; i--)
130 131 {
131 132 if (this.activeObjects[this.pendingRemoval[i]].destroyed)
132 133 this.activeObjects.removeAt(this.pendingRemoval[i]);
134
135 this.pendingRemoval.splice(i, 1);
133 136 }
134 137 }
135 138 }
@@ -109,9 +109,10 @@ class Scene
109 removeObject (obj)
109 removeObject (obj)
110 {
110 {
111 let index = this.activeObjects.indexOf(obj);
111 let index = this.activeObjects.indexOf(obj);
112 if (index >= 0)
112 if (index >= 0 && !obj.destroyed)
113 {
113 {
114 this.pendingRemoval.push(index);
114 if (!this.pendingRemoval.contains(index))
115 this.pendingRemoval.push(index);
115 }
116 }
116 }
117 }
117
118
@@ -126,10 +127,12 @@ class Scene
126 {
127 {
127 this.pendingRemoval.sort();
128 this.pendingRemoval.sort();
128
129
129 for (let i = this.pendingRemoval.length; i >= 0; i++)
130 for (let i = this.pendingRemoval.length - 1; i >= 0; i--)
130 {
131 {
131 if (this.activeObjects[this.pendingRemoval[i]].destroyed)
132 if (this.activeObjects[this.pendingRemoval[i]].destroyed)
132 this.activeObjects.removeAt(this.pendingRemoval[i]);
133 this.activeObjects.removeAt(this.pendingRemoval[i]);
134
135 this.pendingRemoval.splice(i, 1);
133 }
136 }
134 }
137 }
135 }
138 }