Proper way to dispose wade game
Neogene

When disposing a Wade game, i used:

         wade.cancelInputEvents(false); //disable "modal" mode        wade.unloadAllAudio();      //unload audio        wade.unloadAllImages();     //unload images        wade.clearScene();                  wade.stop();

I used these functions calls because the "stop" documentation doesn't declare if are needed or already done under the hood (i suppose yes but in the meantime i prefer to be "safe").

 

But after this code and after hiding the game using the div properties it continued to intercept events and avoiding user normal user interaction in the page so i had to add:
 
wade.stopInputEvents();

Maybe helpful to someone.

 

Maybe should be done in the stop function automatically. 

       
All 4 Comments
Gio

Hi Neogene

 

Thanks for letting us know - I also thought it was done in the stop function. It looks like it  isn't it and it definitely should be. I'm adding it to the list of bug fixes for wade 2.1 

Neogene

Ok, happy to help, the following functions are called inside wade 2.0 and are useless in my case, or there is someone which needs to be always used before stop()?

      wade.cancelInputEvents(false); //disable "modal" mode            wade.unloadAllAudio();      //unload audio        wade.unloadAllImages();     //unload images        wade.clearScene();    
Gio

I would keep most of them to be honest. The one exception being cancelInputEvents() - if you call stopInputEvents() (whcih will be called automatically from wade.stop() in 2.1 as we discussed), then that becomes redundant.

 

You may want to also call wade.deleteCanvases() to actually destroy the canvas elements that were created by wade.

 

Unloading audio and images (as well as clearing the scene) is a different thing to stopping the app, so you can keep doing that. Alternatively (and possibly even better), do this:

wade.stop();wade.stopInputEvents(); // until 2.1 is releasedwade.deleteCanvases();wade = null;

By doing the last thing (wade = null) you are essentially releasing any references to anything loaded and created by wade (including audio, images, etc). Except the references that you may have stored yourself, but the most common pattern is to store everything in wade.app (which is itself a child of wade), so setting wade to null should release all references.

 

This is assuming that you don't need wade for anything else after that - if you do, don't delete canvases (you may want to use wade.removeLayer() though), and don't set wade to null, but unload audio and images.

Neogene

Thank you, undrestood!

Post a reply
Add Attachment
Submit Reply
Login to Reply