Page 1 of 2
Wait/Pause/Sleep?
Posted: Sun Apr 07, 2013 3:01 am
by Knuxchan
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).
So basically something along these lines:
Code: Select all
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).
Re: Wait/Pause/Sleep?
Posted: Sun Apr 07, 2013 4:39 am
by Jackim
this should work
Code: Select all
function love.load()
waiting = true
waitingtimer = 0
end
function love.update(dt)
waitingtimer = waitingtimer + dt
if waitingtimer > 5 then
waiting = false
end
end
Re: Wait/Pause/Sleep?
Posted: Sun Apr 07, 2013 9:17 am
by T-Bone
And about loading levels, I think you're looking for
or
Re: Wait/Pause/Sleep?
Posted: Sun Apr 07, 2013 9:46 am
by Plu
It's probably a better idea to do
The above would keep the CPU running all the time, which probably isn't neccesary.
Re: Wait/Pause/Sleep?
Posted: Sun Apr 07, 2013 10:10 am
by Nixola
Plu wrote:It's probably a better idea to do
The above would keep the CPU running all the time, which probably isn't neccesary.
And this one would freeze LÖVE for those 5 seconds, is it a better idea?
Re: Wait/Pause/Sleep?
Posted: Sun Apr 07, 2013 10:41 am
by Plu
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)
Re: Wait/Pause/Sleep?
Posted: Sun Apr 07, 2013 10:46 am
by daviddoran
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.
Code: Select all
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
Re: Wait/Pause/Sleep?
Posted: Sun Apr 07, 2013 11:14 am
by T-Bone
Even without vsync, Jackim's solution won't max out the cpu. It works just fine.
Re: Wait/Pause/Sleep?
Posted: Sun Apr 07, 2013 12:26 pm
by Plu
Aight, guess that does work better. Sorry about the lousy suggestion
Re: Wait/Pause/Sleep?
Posted: Sun Apr 07, 2013 2:25 pm
by Knuxchan
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.