Loading Resources WHen Needed

I was reading about Performance and Optimazation.  One of the items says to "Load resources lazily.

I’m a newbie and I know this is probably a really dumb question but I’ve never published a game or anything. 

Here goes.   So, my thoughts are the game is downloaded onto the person’s device when they install the game.  Is this correct?

One item in the article says “Load resources lazily - avoid loading resources files until they are actually needed.”

If the person has already downloaded the game to their device, what is mean by not loading redource files until they are needed mean?   How would I do this?

Thanks

Lori

Hi Lori,

Basically, this means that you (as the developer) shouldn’t load resources until right before they’re needed… “resources” meaning images, sprite sheets, audio files, etc. (it doesn’t have anything to do with the user who installs the app on their device). This way, you won’t be occupying memory with resources that you aren’t using at the moment, thus the performance will likely be better.

So in essence, if you’re not using a bunch of images, you should remove them from memory by removing the associated display object and "nil"ing out the reference. Similar with audio, as in, un-load (dispose) the audio file from memory unless it’ll be used soon after.

Hope this helps,

Brent

Right now I am setting up the display objects in Scene Create (I’m using Composor).  So should I set them to isActive = false and isVisible = false and then when I actually need them use a fuction to make them active and visible?  Would I also nil them in in Scene Create?

Right now I have my removeSelf and = nil at the end of the module.

Thanks

Lori

Hi Lori,

Making images invisible will not remove their textures from the texture memory… only removing them entirely will clear that aspect from the memory. As for the scene management, remember that if you place these objects in the scene’s view, they will be automatically removed when you remove the scene… except that, you’ll still need to handle some things manually (cancel and remove timers and transitions, for example). All of this is described in the Composer guide:

http://docs.coronalabs.com/guide/system/composer/index.html

Brent

OK - Thanks.  I will spend some time reading the documentation.   I appreciate the help.

Lori

Hi Lori,

Basically, this means that you (as the developer) shouldn’t load resources until right before they’re needed… “resources” meaning images, sprite sheets, audio files, etc. (it doesn’t have anything to do with the user who installs the app on their device). This way, you won’t be occupying memory with resources that you aren’t using at the moment, thus the performance will likely be better.

So in essence, if you’re not using a bunch of images, you should remove them from memory by removing the associated display object and "nil"ing out the reference. Similar with audio, as in, un-load (dispose) the audio file from memory unless it’ll be used soon after.

Hope this helps,

Brent

Right now I am setting up the display objects in Scene Create (I’m using Composor).  So should I set them to isActive = false and isVisible = false and then when I actually need them use a fuction to make them active and visible?  Would I also nil them in in Scene Create?

Right now I have my removeSelf and = nil at the end of the module.

Thanks

Lori

Hi Lori,

Making images invisible will not remove their textures from the texture memory… only removing them entirely will clear that aspect from the memory. As for the scene management, remember that if you place these objects in the scene’s view, they will be automatically removed when you remove the scene… except that, you’ll still need to handle some things manually (cancel and remove timers and transitions, for example). All of this is described in the Composer guide:

http://docs.coronalabs.com/guide/system/composer/index.html

Brent

OK - Thanks.  I will spend some time reading the documentation.   I appreciate the help.

Lori