"Loading" screen

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
Volgoza
Prole
Posts: 26
Joined: Fri Jul 13, 2012 12:20 pm

"Loading" screen

Post by Volgoza »

Hi all!
You know how i can create "loading" screen?

When game started or game resources loading i want show for users screen where text "Please wait, loaging"

Sorry for my english :awesome:
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: "Loading" screen

Post by Plu »

You have to load most of the stuff in your update loop. Make a game state "loading", and in it, start loading files while updating a number after every file or such. Make sure your update function returns after every few files, so that draw() can be called.
Then in your draw function, draw the word loading and a bar whose length depends on the number of files loaded.

It's not possible to draw a loading bar if you load everything in love.load, because the draw function isn't called while it's executed, and it's also not possible to load all the files in one function call, because draw() is only called whenever update() returns.

Pseudo-code to get the idea across:

Code: Select all

love.load()
  loaded = 0
  files = { 'image.png', 'image2.png', 'image3.png', 'image4.png', 'etc' }
end

love.update(dt)
  if #files then
    file = table.remove( files )
    loadFile( file )
    loaded = loaded + 1
    return
  end
  gamestate = "menu" -- or play, or whatever
end

love.draw()
  love.graphics.print( 400, 20, "Loading" )
  love.graphics.rectangle( "fill", 50, 50, 25*i, 50 )
end
Keep in mind that if you're just loading a few images this proces wil be really, really fast and you probably won't even see it happening. So don't use it unless you really have considerable amounts of loading to do.
User avatar
Volgoza
Prole
Posts: 26
Joined: Fri Jul 13, 2012 12:20 pm

Re: "Loading" screen

Post by Volgoza »

Thx. I see.
Plu wrote:Keep in mind that if you're just loading a few images this proces wil be really, really fast and you probably won't even see it happening. So don't use it unless you really have considerable amounts of loading to do.
Good remark. I think, what i can create function with timer and show this function after each screen-transfer or loading.

The function is ~3 sec.
Resources had times to boot.
Profit!
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: "Loading" screen

Post by Plu »

You can't show a timer counting down unless you spread the loading proces out over multiple calls to the update function. The screen is only updated between update() calls, so you need to spread the loading proces out over about 2 calls per second to get a semi-responsive loading bar.
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: "Loading" screen

Post by micha »

If loading only takes about 3 seconds, then you can leave out a loading bar completely and only write a text like "Loading please wait".

Have a look at the source code of Mari0, it has such a loading screen.
User avatar
SimonLarsen
Party member
Posts: 100
Joined: Thu Mar 31, 2011 4:47 pm
Location: Denmark
Contact:

Re: "Loading" screen

Post by SimonLarsen »

Plu wrote:It's not possible to draw a loading bar if you load everything in love.load, because the draw function isn't called while it's executed, and it's also not possible to load all the files in one function call, because draw() is only called whenever update() returns.
This is not strictly true. This is what is done in the love.run() function:

Code: Select all

...
if love.update then love.update(dt) end -- will pass 0 if love.timer is disabled
if love.graphics then
    love.graphics.clear()
    if love.draw then love.draw() end
end

if love.timer then love.timer.sleep(0.001) end
if love.graphics then love.graphics.present() end
...
Nothing is keeping you from calling love.graphics.clear() and love.graphics.present() yourself. Whether it is good practice is a different matter.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 2 guests