Lazily loading graphics

I am using the Director class and one of my scenes has about 10 options panels all composed of graphic panels and graphic buttons. When I arrive at the scene I display all these graphics off screen so I can animate them on when they are required.

I have a problem though that there is a significant delay when loading this scene.

I have seen the term “lazy loading” mentioned and wondered if rather than loading all these graphics up front, would it make sense to load them every time they are required.

And if so, would calling display.newImageRect for each image every time the image is required be inefficient or due to caching, would not have any adverse affects on performance?

Any advice much appreciated. [import]uid: 7863 topic_id: 7764 reply_id: 307764[/import]

Loading an image is very fast. When I first started using Corona I figured maybe I would need loading screens while waiting for things to load, but I quickly found that there’s no waiting for anything to load. The only thing that was creating load times in my project, loading long music clips, is not a problem once I switched from the old to the new audio API. [import]uid: 12108 topic_id: 7764 reply_id: 27565[/import]

Thanks for the reply jhocking.

Perhaps it is audio files slowing down my screens loading

I have 14 mp3 files loaded in my game.lua file immediately using

gameSounds[“ballsAppearSound”] = audio.load(“audio/whoosh.mp3”)

The audio files range from 4kb to 283kb - all but 2 are under 33kb each.

I am sure I did do a test a while back commenting the audio file loading and it did not appear to make any difference but worth double checking.

I am wondering if it is better to load them some other way or perhaps in main.lua?

Thanks in advance for any advice.

[import]uid: 7863 topic_id: 7764 reply_id: 27679[/import]

I’m wondering about this too.

At current my game is taking about 5 seconds to load in iOS. Just sits at a blank screen until everything loads, which makes it looks like the game is broken or something.

I’ve tried showing a splash and then doing all the audio loading as that is showing, etc., but it just waits 5 ( or so ) seconds and then displays the splash and does the loading. So it’s still that 5 seconds bit.

Tried removing all the audio files from the project to see if that made any difference, but it didn’t. Still a long blank screen. It looks like the app is just loading all the images and sounds and everything before it puts anything up.

I read about using a “default.png” and I tried that too, but to no avail.

Has anyone successfully put up a default screen that shows before all the rest of the stuff loads? If so, could you please share how you did it? :slight_smile:

Thanks. [import]uid: 27145 topic_id: 7764 reply_id: 28111[/import]

Create a lua file for the initial startup of the game.

Ensure the first thing you do is load and display a loading image or something. Then load up all your required initial data.

Then once everything is loaded, move on to your menu or whatever.

That should fix the problem. [import]uid: 6981 topic_id: 7764 reply_id: 28122[/import]

Thanks, infuseddreams.

Yeah, that is essentially what I’m doing. I show a splash screen right at launch and have nothing else loaded, I don’t even reference any of the other .lua files that do any of the loading. So the only thing in the main.lua file is a display.newImage and:

timer.performWithDelay(2500,loadAssets)  

…and the loadAssets function, of course, which does a require and of an assetsManager.lua file and calls the init function within that.

But the loadAssets function shouldn’t be called until after the 2500ms.

Just to check that, I tried to play a sound at the 1000ms mark and the terminal barfed and said that the sound didn’t exist. Yet when I play a sound after loadAssets, no problem.

So it looks like the game doesn’t know that the assets are there until after the loadAssets bit is done, but there is still that 5 second blank screen. To me this means that iOS is loading up everything or verifying it or something before the game launches. Maybe iOS loads the entire app into memory but Corona still has to do its loading stuff before the game can actually use the assets? I dunno.

Anyway, thanks again for the help! :slight_smile: [import]uid: 27145 topic_id: 7764 reply_id: 28131[/import]

It sounds like you need to put Default.png in your app’s directory.

I know you said you tried that, but you probably spelled it wrong. [import]uid: 12108 topic_id: 7764 reply_id: 28139[/import]

Thanks, jhocking!

You were correct. I used “default.png” and not “Default.png”. Ugh. :slight_smile:

Works a charm now. Thanks again. [import]uid: 27145 topic_id: 7764 reply_id: 28520[/import]