Loading the same image sheet multiple times.

Hi All,

I have an image sheet for each of my in game characters, when I’m loading my level and find a reference to a character I load the image sheet and create a sprite from it. My question is, does corona know that this image has been loaded before and read it from memory or does it do a full load. If the latter is true I will create a sort of image pool for reusing images.

Thanks in advance.

**bump**

I could really do with some info on this please.

Honestly don’t know. One way is to create one, create umpteen references to it and see how it effects memory.

One way round it, and it might be a good idea for resources anyway - images, audio, text files, etc - anything that is single instance multiple usage, is to have a central resource manager singleton.

My understanding is that the imageSheet would be loaded into memory multiple times. It’s probably very simple to check if you do some texture memory calls before and after, but in all of my projects I use a sheet loader and central resource manager.

(If you’re using a lot of sheets I highly recommend this method anyway, as loading a dozen @4x sheets can result in significant load time.)

Hi Guys,

Firstly, thank you for your responses.

I thought this might be the case, I will use the resource manager method. I already have a pooling system in place for sprites so adding another for resources shouldn’t be much work.

Thanks guys. 

As far as i’m aware this is not how it works in Corona. When Corona loads an image for the first time it is read from a file and loaded into memory, any subsequent loads are done from the image that is in memory, not subsequent loads from file.

This is provided that you don’t remove the image between subsequent loads. There is a document on the Corona docs site somewhere that explains this. Unfortunately I don’t have the link to hand.

Edit: there is a note on this here on the gotchas section; http://docs.coronalabs.com/api/library/display/newImage.html

I assume the same applies to all Corona image loading api’s

Excellent, well spotted, I’m sure I read through that document and I didn’t see that bit! I just finished the resource manager yesterday too, at least it will be useful for sounds and the such. Thanks for all the help guys.

Just tried this out, and sure enough, I stand corrected. If I load the same imageSheet into memory 10 times using graphics.newImageSheet calls, texture memory does not change.

I think it’s probably good practice to run a resource loader just the same. I can’t be sure if there are any Lua load / CPU hit issues worth mentioning by trying to load an identical imageSheet, but even if it’s fine, it would just be good practice in case Corona changes how things work at any point in the future. (or if you need to port your code, etc.)

Thanks for pointing that out, Gremlin.

**bump**

I could really do with some info on this please.

Honestly don’t know. One way is to create one, create umpteen references to it and see how it effects memory.

One way round it, and it might be a good idea for resources anyway - images, audio, text files, etc - anything that is single instance multiple usage, is to have a central resource manager singleton.

My understanding is that the imageSheet would be loaded into memory multiple times. It’s probably very simple to check if you do some texture memory calls before and after, but in all of my projects I use a sheet loader and central resource manager.

(If you’re using a lot of sheets I highly recommend this method anyway, as loading a dozen @4x sheets can result in significant load time.)

Hi Guys,

Firstly, thank you for your responses.

I thought this might be the case, I will use the resource manager method. I already have a pooling system in place for sprites so adding another for resources shouldn’t be much work.

Thanks guys. 

As far as i’m aware this is not how it works in Corona. When Corona loads an image for the first time it is read from a file and loaded into memory, any subsequent loads are done from the image that is in memory, not subsequent loads from file.

This is provided that you don’t remove the image between subsequent loads. There is a document on the Corona docs site somewhere that explains this. Unfortunately I don’t have the link to hand.

Edit: there is a note on this here on the gotchas section; http://docs.coronalabs.com/api/library/display/newImage.html

I assume the same applies to all Corona image loading api’s

Excellent, well spotted, I’m sure I read through that document and I didn’t see that bit! I just finished the resource manager yesterday too, at least it will be useful for sounds and the such. Thanks for all the help guys.

Just tried this out, and sure enough, I stand corrected. If I load the same imageSheet into memory 10 times using graphics.newImageSheet calls, texture memory does not change.

I think it’s probably good practice to run a resource loader just the same. I can’t be sure if there are any Lua load / CPU hit issues worth mentioning by trying to load an identical imageSheet, but even if it’s fine, it would just be good practice in case Corona changes how things work at any point in the future. (or if you need to port your code, etc.)

Thanks for pointing that out, Gremlin.