Spash screen does not show immediately

I have and app that shows a relatively long list (200 entries) with graphics. The contents of this list is read from a database. In short, it takes some time to read/init/build the GUI elements.

So I want to show a spash screen while these things initialize.

But no matter what I try, there is a large delay before the splash gfx shows. It seems like it waits for the later stuff to finish. As it is now it’s worthless.

So, is there some trick to force some gfx to show immediately?

You can put a tiny delay before doing the database operations to allow enough time for splash screen to show.

Can you not show your splash screen, and put all your initialisation code inside a function which runs after a short delay - enough time to allow the splash screen to load?

Another option is to stagger the loading of your 200 entries so one (or perhaps 5, 10, 20) is drawn per frame. This enables you to do something like show a progress bar while the entries load.

[lua]

local nextItem = 1

local totalItems = 200

local initialise = false

local perFrame = 10

local gameLoop = function ()

      if initialise then

            for a = 1 , perFrame, 1 do

                 

                  if nextItem <= totalItems then

                        – create next item in list from a table

                        nextItem = nextItem + 1

                  else

                        initialise = false

                  end

            end

      end

end

— PUT YOUR SPLASH SCREEN CODE IN SCENE:CREATE

— SET INITIALISE TO TRUE IN SCENE:SHOW (‘DID’ PHASE)

— ADD ENTERFRAME LISTENER CALLED gameLoop IN SCENE:SHOW (‘DID’ PHASE)

[/lua]

Aha… I didn’t see that coming. I was not aware that you had to actually delay the rest of the program for such things to “get breathing room” to show. I’ll try a delay right now. Thanks - to both of you!

Yes! A small delay did the trick! Thanks!

Now I’ll look into the progress bar thing. Makes the waiting part a bit less boring  :slight_smile:

Cool. You’ll have to play around with the perFrame parameter. There’ll be a point where you either load too few per frame and it takes too long to get to the end, or you load too many per frame and the progress bar gets really jerky.

Hmm… interesting. In the scene where the db loading and GUI building happens I aldready have a frameDrawListener function (I use this to manage a DIY scrollView). My plan was to put some code into this to manage the pausing of loaded elements.

But as it turns out it doesn’t seem like this function is called at all before the rest of the stuff is done. It doesn’t seem to matter if I call addEventListener() early or late in the code.

Unfortunately I cannot get any further as long as I don’t get access to this function before “it’s all over”.

I’m not sure what you mean by this. Are you still loading 200 items in one go? Any code that comes after this will not execute until all 200 items are loaded, that includes adding enterFrame listeners.

Well, it’s a bit complicated.

I first build an array of all the entries in the list of birds that comes with the version of the app.

Then I have to merge this list with the local data that the user may have changed.

Then I have to sort/filter the list acccording to the settings of the user.

Then I build the GUI from this data.

There quite some loops going on… It’s not trivial to use the model that you sketched without a major rewrite of the loading code. I was just playing around to see if I could use the frameRedrawListener() to something. Turns out it’s difficult.

I’m trying to add the call addEventLister(“enterFrame”, frameRedrawListener) before anything else, if that is what you mean.

My (simplified) frame function looks like this:

local FrameNum = 0 local frameRedrawListener = function(e) FrameNum = FrameNum + 1 print(FrameNum) end print("Calling addEventListener") Runtime:addEventListener( "enterFrame", frameRedrawListener ) print("Called addEventListener")

This results in a log looking more or less like this:

Calling addEventListener Called addEventListener isTablet = true preloadBirdImageData() - start 1 / 196 2 / 196 ... 195 / 196 196 / 196 guiBuildList() - frames used = 0 preloadBirdImageData() - end shouldUpdateBirdList is TRUE Composite sort string: ORDER BY name ASC db:nrows(SELECT \* FROM birdTable ORDER BY name ASC ) scene:show:will guiBuildList() - start guiBuildList() - frames used = 0 guiBuildList() - end 1 2 3

The addEventListener is clearly called before the “heavy stuff” starts. Still frameRedrawListenerer() seems only to be “active” after everything else is done.

Although you add the listener, because the following code takes so much CPU time it doesn’t get a chance to run at all.

Corona refreshes the display 30/60 times a second (and runs any enterFrame listener functions), but only if the CPU is available. Once you embark on loading 200 items in one go, it’s completely locked up until all that code completes.

The work to merge/sort/filter the data shouldn’t take up too much CPU time.

Once that’s in order, you could do the bit that loads the images/text for each item in the enterFrame listener, breaking the task into manageable chunks that don’t lock up the cpu and allows the display to refresh.

Ok, that sounds plausible. I’ll try to control the GUI creation part from the enterFrame listener as you recommend. Need some time though…  :slight_smile:

Thanks again for your kind help!

Some time later: Yep! This method works very well!

The splash gfx loads instantly and actually  everything seems to be more responsive! After running a filter, the new list is redrawn lightning fast. Obviously a pause after a few entries is made is golden!

Great stuff! Thanks again!

You can put a tiny delay before doing the database operations to allow enough time for splash screen to show.

Can you not show your splash screen, and put all your initialisation code inside a function which runs after a short delay - enough time to allow the splash screen to load?

Another option is to stagger the loading of your 200 entries so one (or perhaps 5, 10, 20) is drawn per frame. This enables you to do something like show a progress bar while the entries load.

[lua]

local nextItem = 1

local totalItems = 200

local initialise = false

local perFrame = 10

local gameLoop = function ()

      if initialise then

            for a = 1 , perFrame, 1 do

                 

                  if nextItem <= totalItems then

                        – create next item in list from a table

                        nextItem = nextItem + 1

                  else

                        initialise = false

                  end

            end

      end

end

— PUT YOUR SPLASH SCREEN CODE IN SCENE:CREATE

— SET INITIALISE TO TRUE IN SCENE:SHOW (‘DID’ PHASE)

— ADD ENTERFRAME LISTENER CALLED gameLoop IN SCENE:SHOW (‘DID’ PHASE)

[/lua]

Aha… I didn’t see that coming. I was not aware that you had to actually delay the rest of the program for such things to “get breathing room” to show. I’ll try a delay right now. Thanks - to both of you!

Yes! A small delay did the trick! Thanks!

Now I’ll look into the progress bar thing. Makes the waiting part a bit less boring  :slight_smile:

Cool. You’ll have to play around with the perFrame parameter. There’ll be a point where you either load too few per frame and it takes too long to get to the end, or you load too many per frame and the progress bar gets really jerky.

Hmm… interesting. In the scene where the db loading and GUI building happens I aldready have a frameDrawListener function (I use this to manage a DIY scrollView). My plan was to put some code into this to manage the pausing of loaded elements.

But as it turns out it doesn’t seem like this function is called at all before the rest of the stuff is done. It doesn’t seem to matter if I call addEventListener() early or late in the code.

Unfortunately I cannot get any further as long as I don’t get access to this function before “it’s all over”.

I’m not sure what you mean by this. Are you still loading 200 items in one go? Any code that comes after this will not execute until all 200 items are loaded, that includes adding enterFrame listeners.

Well, it’s a bit complicated.

I first build an array of all the entries in the list of birds that comes with the version of the app.

Then I have to merge this list with the local data that the user may have changed.

Then I have to sort/filter the list acccording to the settings of the user.

Then I build the GUI from this data.

There quite some loops going on… It’s not trivial to use the model that you sketched without a major rewrite of the loading code. I was just playing around to see if I could use the frameRedrawListener() to something. Turns out it’s difficult.

I’m trying to add the call addEventLister(“enterFrame”, frameRedrawListener) before anything else, if that is what you mean.

My (simplified) frame function looks like this:

local FrameNum = 0 local frameRedrawListener = function(e) FrameNum = FrameNum + 1 print(FrameNum) end print("Calling addEventListener") Runtime:addEventListener( "enterFrame", frameRedrawListener ) print("Called addEventListener")

This results in a log looking more or less like this:

Calling addEventListener Called addEventListener isTablet = true preloadBirdImageData() - start 1 / 196 2 / 196 ... 195 / 196 196 / 196 guiBuildList() - frames used = 0 preloadBirdImageData() - end shouldUpdateBirdList is TRUE Composite sort string: ORDER BY name ASC db:nrows(SELECT \* FROM birdTable ORDER BY name ASC ) scene:show:will guiBuildList() - start guiBuildList() - frames used = 0 guiBuildList() - end 1 2 3

The addEventListener is clearly called before the “heavy stuff” starts. Still frameRedrawListenerer() seems only to be “active” after everything else is done.