Is there a Wait/Pause/Sleep method or function that exists for LOVE? Basically, I want to show a screen that says 'Stage 1 Start' for 5 seconds then goes to the next level file (level1.lua).
love.graphics.print("Stage 1 Start", 100,200) --show text on the screen
wait(5) --wait 5 seconds
love.filesystem.load("level1.lua")() --go to level 1 (btw, is this the correct syntax to load a level? Because I couldn't find anything in the documentation or the forums about simple level generation).
function love.load()
waiting = true
waitingtimer = 0
end
function love.update(dt)
waitingtimer = waitingtimer + dt
if waitingtimer > 5 then
waiting = false
end
end
Does it flush the graphics buffer? I thought it would keep the screen frozen in place? If it makes the screen black it's indeed not a good idea, and I also misunderstood the purpose of the function.
(Of course if you want animations in your loading screen it's also not a very good idea)
It's definitely a better idea to use Jackim's approach.
That way the game won't lock up, you can keep drawing (maybe you'll have a loading animation in the future) and you can keep receiving input (e.g. skipping the loading screen by pressing any key).
The only thing I'd change is how the timer is implemented.
With the code below you can just set the loading variable to the number of seconds to wait, anywhere in your program.
local loading = -1
function love.load()
-- start our 5s loading timer
loading = 5
end
function love.update(dt)
if loading > 0 then
loading = loading - dt
elseif loading == 0 then
loading = -1
end
end
function love.draw(dt)
if loading > 0 then
-- draw the loading screen
end
end
This is weird. It's not working for me. It seems to be ignoring the dt argument, so the timer is never going off. I passed the dt argument in my update function. I even tried printing out the value of dt on the screen and nothing shows up.