Displaying Image From Time To Time?

I’m wondering what is the best way to have an image show from time to time. Should I load the image and just set the alpha to 0 until I need it, or should I load in the image when I need it and then remove the image? Or is there a better way then both of those even?

Thanks

Both methods are acceptable, but remember that “hidden” images still take up memory (and more importantly, texture memory). So, if you have dozens of images that you’re swapping in and out visually (using alpha=0 or isVisible=false), remember that they’re still being regarded in the display hierarchy and in texture memory.

On the other hand, if you create and destroy images, and do this process a considerable number of times in a time-critical step, you might see a small performance skip, especially if the images are large in file size.

Hope this helps,

Brent

Okay for the game I have these images show up maybe once every couple of minutes. I used them for maybe 30 seconds and then hide them. I load all the images at the start of the game 22 of them 17 of which stay there all the time and 5 of them I hide and show as needed. Performance skip won’t be a huge issue as long as it’s a simple blip and not like 10 seconds worth of dropped framerate. In my game do you think it sounds best to load in the images as I need them? I think it seems that way.

Yes, for 5 images that you load occasionally, I think you can just create and remove them as needed (no need to hide them and take up texture memory).

Okay cool I will change it. If I remove my image using :removeSelf() does it remove the reference to the group it’s in as well?

dmglakewood

When it doubt try the easy (fast to code) way first then measure.

local function round(val, n)  if (n) then     return math.floor( (val \* 10^n) + 0.5) / (10^n)   else     return math.floor(val+0.5)   end end local function monitorMem()     collectgarbage()     print( "MemUsage: " .. round(collectgarbage("count"),4) .. " KB")     local textMem = system.getInfo( "textureMemoryUsed" ) / (1024 \* 1024)     print( "TexMem:   " .. textMem .. " MB" ) end   

You can call ‘monitorMem()’ before the code where you build your scene and after it to get a rough estimate of how much memory you will use.

If you feel it is using too much memory, you can always try the harder but more efficient design.

-Ed

PS - See this link to get your answer about how to properly remove the object to get it garbage collected: http://www.coronalabs.com/blog/2011/08/15/corona-sdk-memory-leak-prevention-101/

@dmglakewood,

Ed is correct, and here’s another recent blog tutorial on the issue of cleaning up memory and such:

http://www.coronalabs.com/blog/2013/04/02/cleaning-up-display-objects-andlisteners/

Brent

Both methods are acceptable, but remember that “hidden” images still take up memory (and more importantly, texture memory). So, if you have dozens of images that you’re swapping in and out visually (using alpha=0 or isVisible=false), remember that they’re still being regarded in the display hierarchy and in texture memory.

On the other hand, if you create and destroy images, and do this process a considerable number of times in a time-critical step, you might see a small performance skip, especially if the images are large in file size.

Hope this helps,

Brent

Okay for the game I have these images show up maybe once every couple of minutes. I used them for maybe 30 seconds and then hide them. I load all the images at the start of the game 22 of them 17 of which stay there all the time and 5 of them I hide and show as needed. Performance skip won’t be a huge issue as long as it’s a simple blip and not like 10 seconds worth of dropped framerate. In my game do you think it sounds best to load in the images as I need them? I think it seems that way.

Yes, for 5 images that you load occasionally, I think you can just create and remove them as needed (no need to hide them and take up texture memory).

Okay cool I will change it. If I remove my image using :removeSelf() does it remove the reference to the group it’s in as well?

dmglakewood

When it doubt try the easy (fast to code) way first then measure.

local function round(val, n)  if (n) then     return math.floor( (val \* 10^n) + 0.5) / (10^n)   else     return math.floor(val+0.5)   end end local function monitorMem()     collectgarbage()     print( "MemUsage: " .. round(collectgarbage("count"),4) .. " KB")     local textMem = system.getInfo( "textureMemoryUsed" ) / (1024 \* 1024)     print( "TexMem:   " .. textMem .. " MB" ) end   

You can call ‘monitorMem()’ before the code where you build your scene and after it to get a rough estimate of how much memory you will use.

If you feel it is using too much memory, you can always try the harder but more efficient design.

-Ed

PS - See this link to get your answer about how to properly remove the object to get it garbage collected: http://www.coronalabs.com/blog/2011/08/15/corona-sdk-memory-leak-prevention-101/

@dmglakewood,

Ed is correct, and here’s another recent blog tutorial on the issue of cleaning up memory and such:

http://www.coronalabs.com/blog/2013/04/02/cleaning-up-display-objects-andlisteners/

Brent