Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
arthurgps2
Prole
Posts: 5
Joined: Tue Jan 31, 2017 9:12 pm
Contact:

So I would like to make a loading screen for my project at the startup, instead of that white screen. I've looked through this forum, but I couldn't find a very clear solution. I want an image written "Loading" to appear while other stuff is loading. Oh, and please explain every part of the code so I can understand,
Oh, and I also like to use the love.draw() and love.update() functions like this:

Code: Select all

function draw()
--Code
end

function update(dt)
--Code
end

function love.draw()
--Maybe some other stuff
draw()
end

function love.update(dt)
--Maybe some other stuff
update(dt)
end


pgimeno
Party member
Posts: 1531
Joined: Sun Oct 18, 2015 2:58 pm

If you only want a static image, you could get away with something like this:

Code: Select all

love.graphics.clear()
love.graphics.present()

Look up the respective functions to know how they're used. Ignore the note about love.run, because you don't want the Loading screen in the main loop, which is what love.run deals with.
Thrust II Reloaded - GifLoad for Löve - GSpöt GUI - My NotABug.org repositories - portland (mobile orientation)
The MS-Github repositories I had have been closed after the acquisition announcement and will be removed in the near future.

zorg
Party member
Posts: 2528
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Um, you shouldn't do that? newImage is wasteful like that?
Also what note about love.run? and where's the explanation that that code looks like love.run's part, and you shouldn't even need to call clear nor present?
What's happening :V
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.

pgimeno
Party member
Posts: 1531
Joined: Sun Oct 18, 2015 2:58 pm

Here's a complete main.lua (use any random image for the loading screen)

Code: Select all

love.graphics.clear()
love.graphics.present()

love.timer.sleep(3) -- simulates 3 second load time

function love.draw()
end

The love.run note I was talking about is in love.graphics.present.

Edited to add: Ok, that was a bit too terse. Let me expand a bit.
1) love.graphics.clear() is needed because the contents of the screen are undefined without it. The main loop in love.graphics.run() normally takes care of that, but the whole intention here is being able to show something before (or within) love.load, which happens before the main loop.
2) The image won't be used for anything else. If you need the dimensions then sure, use a variable to hold it and let you get the size then draw it.
3) love.graphics.present() is what actually shows on the screen the image that was previously drawn, as the docs say.
Last edited by pgimeno on Mon Jan 14, 2019 1:11 am, edited 1 time in total.
Thrust II Reloaded - GifLoad for Löve - GSpöt GUI - My NotABug.org repositories - portland (mobile orientation)
The MS-Github repositories I had have been closed after the acquisition announcement and will be removed in the near future.

zorg
Party member
Posts: 2528
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

That said, i tested your solution, and on my end, the initial SDL window with the initialized contents (ie white, or apparently black on OSX, according to slime) won't "replace" that startup phenomenon, (and in my case, there's an added transparent window effect as well, for a split second after the initial whiteness, on win7), it'll just show the image -after- all that happens... which is probably not what OP expects as a solution.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.

pgimeno
Party member
Posts: 1531
Joined: Sun Oct 18, 2015 2:58 pm

Maybe a love.event.pump() is needed? Could you try this? (also, I've edited my post to expand a bit)

Code: Select all

love.graphics.clear()
love.graphics.present()
love.event.pump()

love.timer.sleep(3) -- simulates 3 second load time

function love.draw()
end

Thrust II Reloaded - GifLoad for Löve - GSpöt GUI - My NotABug.org repositories - portland (mobile orientation)
The MS-Github repositories I had have been closed after the acquisition announcement and will be removed in the near future.

zorg
Party member
Posts: 2528
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Tried that, nothing different; i could try to capture a gif with licecap of how it's on my end?

Also, if this behaviour of SDL can't be mitigated, i might look into spawning the window outside the desktop area, and moving it back after 3 secs or so, so that that init thing won't show at all.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.

pgimeno
Party member
Posts: 1531
Joined: Sun Oct 18, 2015 2:58 pm

Well, if this doesn't work, then there's little else that can be done: window creation is delayed until the very last moment where it can be done, and right after that come the rest of unavoidable things.

conf.lua:

Code: Select all

function love.conf(c)
c.window = nil
end

main.lua:

Code: Select all

do
love.window.setMode(800, 600)
img = love.graphics.newImage(img)
love.graphics.clear()
love.graphics.draw(img)
love.graphics.present()
love.event.pump()
end

love.timer.sleep(3)

function love.draw()
end

Thrust II Reloaded - GifLoad for Löve - GSpöt GUI - My NotABug.org repositories - portland (mobile orientation)
The MS-Github repositories I had have been closed after the acquisition announcement and will be removed in the near future.

zorg
Party member
Posts: 2528
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

I attached the gif i captured; looks like it can't be avoided this way.
Attachments
sdlinit.gif (1.86 MiB) Viewed 741 times
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.

pgimeno
Party member
Posts: 1531
Joined: Sun Oct 18, 2015 2:58 pm