Wait/Pause/Sleep?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Knuxchan
Prole
Posts: 15
Joined: Wed Apr 03, 2013 4:06 am

Wait/Pause/Sleep?

Post 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).
Jackim
Prole
Posts: 12
Joined: Wed Apr 03, 2013 3:02 am
Location: Canada

Re: Wait/Pause/Sleep?

Post 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
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: Wait/Pause/Sleep?

Post by T-Bone »

And about loading levels, I think you're looking for

Code: Select all

require "level1"
or

Code: Select all

level1 = require "level1"
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: Wait/Pause/Sleep?

Post by Plu »

It's probably a better idea to do

Code: Select all

love.timer.sleep( 5 )
The above would keep the CPU running all the time, which probably isn't neccesary.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Wait/Pause/Sleep?

Post by Nixola »

Plu wrote:It's probably a better idea to do

Code: Select all

love.timer.sleep( 5 )
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?
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: Wait/Pause/Sleep?

Post 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)
User avatar
daviddoran
Prole
Posts: 30
Joined: Sun Mar 24, 2013 5:35 am

Re: Wait/Pause/Sleep?

Post 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
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: Wait/Pause/Sleep?

Post by T-Bone »

Even without vsync, Jackim's solution won't max out the cpu. It works just fine.
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: Wait/Pause/Sleep?

Post by Plu »

Aight, guess that does work better. Sorry about the lousy suggestion :P
Knuxchan
Prole
Posts: 15
Joined: Wed Apr 03, 2013 4:06 am

Re: Wait/Pause/Sleep?

Post 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.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest