Timer to end game
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Timer to end game
How do I make an easy timer to end a game after like 2 seconds. I made a small asteroids game and once you win you can shoot into the air. I just want to make a timer so you can only shoot in the air for 2 seconds and then the window closes
Re: Timer to end game
You can use a timer library or make your own. If you decide to use one, hump.timer is good. It can be overkill for just one timer, though, so if you decide to make your own, it's easy. Have a variable that tells if the timer is active. If it is, accumulate dt in another variable until the value exceeds the set timer. For example:
You then set timerActive = true when the player wins, so that the timer starts counting.
Code: Select all
local timerActive = false
local timerDuration = 0
function love.update(dt)
if timerActive then
timerDuration = timerDuration + dt
-- after 2 seconds, quit
if timerDuration >= 2 then
love.event.quit()
end
end
... rest of love.update here
end
Who is online
Users browsing this forum: Google [Bot] and 5 guests