Loading Screen? Please help.

I want a loading screen with the image I am using. I put the image in the main.lua now how do I make that screen only last for lets say 3 seconds before it automatically switches to the next.lua??? please respond quick thanks a ton!

Hey,

If you’re using storyboard then one way to do this is to use a timer within the enterScene() function (which gets called once the scene enters the user’s view) which will call storyboard.gotoScene( “<sceneName>”, optionsTable ) after 3 seconds.

Something like this…

[lua]

function scene:enterScene( event ) 

    …

    <code to display BG image here, or in createScene() or willEnterScene()…>

    …

    local myTimer = timer.performWithDelay( 3000, function() storyboard.gotoScene("<nextScene>", options); end )

    …

end

[/lua]

Something like the above should do the trick…

Rich

thanks! now how do I go to the next .lua file after main.lua I want to go into the main menu of my game now. 

Hey,

The code I posted should allow that dude.  If you are not using storyboard inside your main.lua then just create and display the background images inside main.lua and then invoke the timer function (containing the call to the next class) afterwards.

Rich

I am against using a timer to change scenes. You are potentially adding more loading time to your app than is needed. For instance say your next scene only took 500ms to load. Using a fixed time loading change, you are adding 2500 ms to your loading time for no good reason.

If you are just using a static loading screen I would do this:

  1. When needed switch to loading scene.

  2. Loading scene’s create scene function loads/displays your loading image.

  3. Loading scene’s enterScene function simply has a storyboard.gotoScene call, which you can pass which scene to change to via event.params.

This way, as soon as your next scene is loaded it will go to it, rather than adding an arbitrary delay to your loading process.

My 2¢

That’s a great solution for static loaders (*borrows*…)  

For animated loaders, you’d have to use timers simply because there’s no way to get a report back when an asset is loaded. If you know the assets ahead of time, you could adjust timer duration based on file size, but in many cases that’s just a lot of unneeded code.

Well, given that you don’t really want a loading screen to literally pop up for a few split seconds, I don’t really see any problem with using a timer.  If it’s a really flash looking animated loading screen then you might want the user to see this.  I guess I haven’t been doing this long enough to have experienced a scene taking a considerable amount of time to load up.

Rich

That is true, but also raises another argument. If the loading time is only going to be a few split seconds, why bother showing a loading screen at all?

In AAA (console) games they generally advise on just using a black screen if the loading time is under x amount of seconds for instance. (I’m talking about back in the SNES/Genesis days though… although the rule still seems to apply today)

I’m not trying to cause an argument here, just raising some valid points (my 2¢ as it were) :slight_smile:

haha, for sure.

I wasn’t either  :slight_smile: <rolls down sleeves and unclenches fists>  :wink:

Rich

can someone just give me the code so it will load to my next .lua file I have 4 .lua files the config, main, my main menu for the game, and the game itself. just give me the code for it to switch from main to my main menu. please thanks!

If you look at the Business sample app on our github repository (https://github.com/coronalabs/business-app-sample)  you will see in the main.lua near the bottom how we implemented a temporary splash screen before firing off the main screen.

Rob

Do you need a loading screen or a splash screen -

http://docs.coronalabs.com/guide/distribution/buildSettings/index.html#launchimage

Dave

Hey,

If you’re using storyboard then one way to do this is to use a timer within the enterScene() function (which gets called once the scene enters the user’s view) which will call storyboard.gotoScene( “<sceneName>”, optionsTable ) after 3 seconds.

Something like this…

[lua]

function scene:enterScene( event ) 

    …

    <code to display BG image here, or in createScene() or willEnterScene()…>

    …

    local myTimer = timer.performWithDelay( 3000, function() storyboard.gotoScene("<nextScene>", options); end )

    …

end

[/lua]

Something like the above should do the trick…

Rich

thanks! now how do I go to the next .lua file after main.lua I want to go into the main menu of my game now. 

Hey,

The code I posted should allow that dude.  If you are not using storyboard inside your main.lua then just create and display the background images inside main.lua and then invoke the timer function (containing the call to the next class) afterwards.

Rich

I am against using a timer to change scenes. You are potentially adding more loading time to your app than is needed. For instance say your next scene only took 500ms to load. Using a fixed time loading change, you are adding 2500 ms to your loading time for no good reason.

If you are just using a static loading screen I would do this:

  1. When needed switch to loading scene.

  2. Loading scene’s create scene function loads/displays your loading image.

  3. Loading scene’s enterScene function simply has a storyboard.gotoScene call, which you can pass which scene to change to via event.params.

This way, as soon as your next scene is loaded it will go to it, rather than adding an arbitrary delay to your loading process.

My 2¢

That’s a great solution for static loaders (*borrows*…)  

For animated loaders, you’d have to use timers simply because there’s no way to get a report back when an asset is loaded. If you know the assets ahead of time, you could adjust timer duration based on file size, but in many cases that’s just a lot of unneeded code.

Well, given that you don’t really want a loading screen to literally pop up for a few split seconds, I don’t really see any problem with using a timer.  If it’s a really flash looking animated loading screen then you might want the user to see this.  I guess I haven’t been doing this long enough to have experienced a scene taking a considerable amount of time to load up.

Rich

That is true, but also raises another argument. If the loading time is only going to be a few split seconds, why bother showing a loading screen at all?

In AAA (console) games they generally advise on just using a black screen if the loading time is under x amount of seconds for instance. (I’m talking about back in the SNES/Genesis days though… although the rule still seems to apply today)

I’m not trying to cause an argument here, just raising some valid points (my 2¢ as it were) :slight_smile:

haha, for sure.

I wasn’t either  :slight_smile: <rolls down sleeves and unclenches fists>  :wink:

Rich