Time

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.
Post Reply
User avatar
Semeon
Prole
Posts: 36
Joined: Tue Jul 12, 2016 1:35 pm

Time

Post by Semeon »

Hey,
Is it possible to perform a certain thing (function) for a specific time for example 2 seconds.
After some research I think it has to do something with frames but not quite sure please explain me how it is done thank you!
steven777
Prole
Posts: 35
Joined: Tue Jul 12, 2016 4:48 am

Re: Time

Post by steven777 »

update variable every revolution

tick = tick +1 -- updated every 1 cycle. 1/100 apx a second

adds time to tick..

tick = tick+dt -- updated every second
steven777
Prole
Posts: 35
Joined: Tue Jul 12, 2016 4:48 am

Re: Time

Post by steven777 »

this is basic and probably a really poor example but yea it works lol

function keeptime()
tick = tick +1
if tick > 9 and tick < 10
-- call a function
end

if tick > 10 then
tick = 0
end

end

remember that this is based on revolutions ( how many times the script is called )

change tick = tick +1 to tick = tick +dt if you want per second...
User avatar
Inny
Party member
Posts: 652
Joined: Fri Jan 30, 2009 3:41 am
Location: New York

Re: Time

Post by Inny »

You can use cron.lua. It's a very simple library, all you need to do is on the love.update function, call update with the clock.

Code: Select all

myEvent = cron.after(5, function() print("This happens after 5 seconds") end)

function love.update(dt)
  myEvent:update(dt)
end
There are plenty of other timer libraries you can use, but the idea is the same for most of them, keep adding up the dt values that come from love.update.
User avatar
Tanner
Party member
Posts: 166
Joined: Tue Apr 10, 2012 1:51 am

Re: Time

Post by Tanner »

HUMP's Timer lib has the function you want: http://hump.readthedocs.io/en/latest/ti ... mer.during
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 214 guests