How do you do a loading screen ?

Hi,

Seen a few Corona apps that have a loading screen but can’t figure out how to one properly.

I can put up a image with a timer and it says loading, then after the timer runs out load my game but I want to actually load the game while the loading screen is showing and even have a progress bar.

Cheers,

Dave [import]uid: 117617 topic_id: 22487 reply_id: 322487[/import]

What about this:

local background = display.newImage( "splash.jpg", true )  
  
  
localGroup:insert( background )  
  
local function listener( event )  
  
 --- Continue loading game  
  
end  
  
timer.performWithDelay(2000, listener,1)  
  

It waits 2 seconds before continuing… [import]uid: 50459 topic_id: 22487 reply_id: 89660[/import]

Just curious, what kind of heavy data are you loading? Huge images? Are you processing data files or doing FTP/HTTP transactions? In general, how long does your loading sequence take?

I believe that Lua works through a function sequentially, line by line, completing one thing before doing the next. So if you load 20 huge images in a function, you could set a boolean flag variable and “listen” for it to be true while you load your images. At the end of your loading sequence, set it to “true”… this should then tell the listener that everything is loaded.

For example…

local isGameLoaded = false  
  
local function listenForGameLoaded( event )  
 if ( isGameLoaded == true ) then  
 Runtime:removeEventListener( "enterFrame", listenForGameLoaded ) --remove listener  
 --clear "loading" image and proceed  
 end  
end  
  
local function loadingSequence()  
 Runtime:addEventListener( "enterFrame", listenForGameLoaded )  
 --load big images, do FTP, etc.  
 isGameLoaded = true  
end  
  
--start loading sequence  
loadingSequence()  

You’ll have to test this… I can’t confirm it will work properly, but it’s worth a shot. :slight_smile: Maybe somebody else has a tested and proven solution.

Brent Sorrentino
Ignis Design
[import]uid: 9747 topic_id: 22487 reply_id: 89662[/import]

Hi,

It’s loads of graphics am loading.

At first I was using StoryBoard and all the graphics where in Scene 2, so you title screen popped up dead quick but when you pressed Start there was a delay while it loaded Scene 2.

I asked about pre-loading a scene but got no replies, so scrapped StoryBoard and just loaded everything at startup but hidden the game. When you press Start now it’s instant but loading the game takes a little bit longer.

At the moment its not that noticeable but as I issue new updates for new levels etc… the delay will become longer and longer.

EDIT: Didn’t know about the EnterFrame option, just reading up on it now.

Dave [import]uid: 117617 topic_id: 22487 reply_id: 89666[/import]

I think if you really need all the graphics you’re loading when you start the game, just display the splash screen or display a percentage you have loaded to inform the user.

The more information you give, the more distracted they get the shorter the load time feels like :slight_smile:

[import]uid: 50459 topic_id: 22487 reply_id: 89749[/import]

I’m currently working on a plug and play solution to displaying an animated loading screen. This could contain say a spinning cog or circle, to show you that it is loading.

It’s still in planning stage but i was thinking of doing this.

  
initLoadingScreen(  
 {  
 bkImage = "whatever.png", -- your background loading image  
 loadingAnim = "cog.png", -- Your animated image (that rotates)  
 imageData = imgTbl, -- Table containing strings of your filenames (of all images you want to load  
 soundData = sndTbl, -- Same as above but for sounds  
 ioData = dataTbl, --Same as above but for data.  
 onComplete = loadGame -- Function you want to call when the loading is done.  
 }  
)   

Then have it execute a callback when it’s complete so you can change to the relevant scene. I’m just toying with the overall design plan (that is currently in my head) to ensure it’s easy to use and doesn’t introduce memory leaks.

So maybe in a few days (no promises) I should have something to share with you all. [import]uid: 84637 topic_id: 22487 reply_id: 90012[/import]

Hey Danny did you get any further with this? [import]uid: 58885 topic_id: 22487 reply_id: 97011[/import]

Hi Chevol. I actually been so busy since i made that post that I haven’t had time to look into it. I will put it on my Todo list today [import]uid: 84637 topic_id: 22487 reply_id: 97024[/import]

No worries buddy, was just wondering. [import]uid: 58885 topic_id: 22487 reply_id: 97038[/import]

Did you make any progress on this Danny? Seems like it would be really helpful to a big chunk of the community. [import]uid: 129450 topic_id: 22487 reply_id: 109060[/import]

We are discussing this internally, however something can be done to a degree in pure lua [import]uid: 84637 topic_id: 22487 reply_id: 109061[/import]