Page 1 of 1
I'm new to LOVE lua
Posted: Wed Nov 13, 2013 1:26 am
by Jeff Xu
Hi, I'm new to LOVE 2D's lua... I have previous experience with some LUA, but I'm not sure how to do somethings.
Is there a wait() statement? or a way to delay something?
Thanks
(:
Re: I'm new to LOVE lua
Posted: Wed Nov 13, 2013 2:30 am
by DaedalusYoung
Well, there is
love.timer.sleep(), but it's not recommended to use that, as it actually halts the entire program.
The common way of waiting is done by using states and a counter variable. Increase the counter every frame by
dt until it reaches a certain value.
Example code:
Code: Select all
love.load()
timer = 0
state = "wait"
end
love.update(dt)
if state == "wait" then
timer = timer + dt
if timer >= 5 then -- after 5 seconds
state = "continue" -- the game state is changed
end
end
end
love.draw()
if state == "wait" then
love.graphics.print("Not doing anything...", 64, 64) -- this message shows for the first 5 seconds
elseif state == "continue" then
love.graphics.print("Going to the next game state.", 64, 64) -- this message shows after that, until you quit LOVE
end
end