MCPcopy Create free account
hub / github.com/melonjs/melonJS / #cleanup

Method #cleanup

packages/melonjs/src/loader/loadingscreen.js:159–184  ·  view source on GitHub ↗

* Remove loading screen children and unload the logo * @ignore

()

Source from the content-addressed store, hash-verified

157 * @ignore
158 */
159 #cleanup() {
160 this.#cleanedUp = true;
161
162 // Tolerate the case where the user's preload callback already
163 // removed our children — `world.reset()` is a common pattern
164 // in user setup code (the benchmark example does this), and
165 // it nukes every world child including our progress bar +
166 // logo. Calling `removeChild` on a non-child throws "Child is
167 // not mine.", which propagates up through the LOADER_COMPLETE
168 // emit chain and corrupts downstream state.
169 if (this.progressBar) {
170 if (this.#app.world.hasChild(this.progressBar)) {
171 this.#app.world.removeChild(this.progressBar);
172 }
173 this.progressBar = null;
174 }
175 if (this.logoSprite) {
176 if (this.#app.world.hasChild(this.logoSprite)) {
177 this.#app.world.removeChild(this.logoSprite);
178 }
179 this.logoSprite = null;
180 }
181
182 // unload the logo image
183 unload({ name: "melonjs_logo", type: "image" });
184 }
185
186 /**
187 * Called by engine before deleting the object

Callers 1

onDestroyEventMethod · 0.95

Calls 3

unloadFunction · 0.90
hasChildMethod · 0.80
removeChildMethod · 0.80

Tested by

no test coverage detected