one second timer
one second timer
how would i say every 1 second add 1 to x?
- Jasoco
- Inner party member
- Posts: 3727
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: one second timer
There are a few timer libraries out there. Look up Cron I believe. Or Hump which has a Timer part.
Cron: http://love2d.org/forums/viewtopic.php?f=5&t=2882
Hump: http://love2d.org/forums/viewtopic.php?f=5&t=1795
With Cron you'd use the cron.every to create a simple function that would perform your addition task every second.
Cron: http://love2d.org/forums/viewtopic.php?f=5&t=2882
Hump: http://love2d.org/forums/viewtopic.php?f=5&t=1795
With Cron you'd use the cron.every to create a simple function that would perform your addition task every second.
Re: one second timer
If you want a basic function, use two variables like this. (It goes in love.update)
One of them is integer based and the other is a float that collects pieces of passing time from the dt that love.update() gets. Then every time more than a second has been collected, that seconds gets moved to the other function.
(You'll have to define baseTimer and seconds, they need to start at 0 )
Alternatively, if it's just about the number, you can also just count time as a float and then use its rounded-down version:
One of them is integer based and the other is a float that collects pieces of passing time from the dt that love.update() gets. Then every time more than a second has been collected, that seconds gets moved to the other function.
(You'll have to define baseTimer and seconds, they need to start at 0 )
Code: Select all
baseTimer = baseTimer + dt
if baseTimer > 1 then
baseTimer = baseTimer - 1
seconds = seconds + 1
end
Code: Select all
baseTimer = baseTimer + dt
-- now you can use math.floor( baseTimer ) to get the number of seconds as an integer
Who is online
Users browsing this forum: Google [Bot] and 4 guests