Best way to do a timer?

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.
User avatar
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain

Re: Best way to do a timer?

Post by kikito » Thu Oct 23, 2014 4:47 pm

Zilarrezko wrote:I'm sure kikito's library compensates for these things. He and/or she thinks of everything. ;)
Well cron is simpler than your example in the sense that there is no "speed". cron timers just use whatever dt you pass them. You can still do do timer:update(2*dt) to make a timer go twice as faster or timer:update(0.5*dt) to make it go twice as slow.

cron.lua does handle a different kind of "spill". If your dt is big enough, periodic timers get executed as many times as necessary, instead of once, which is the "naive" implementation (here's the spec for that, in case you are curious). The trick is using a "while" instead of an "if" to gradually remove dt "in steps" when it is greater than the frequency.
When I write def I mean function.

User avatar
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands

Re: Best way to do a timer?

Post by Robin » Fri Oct 24, 2014 10:55 am

Zilarrezko wrote:He and/or she thinks of everything. ;)
They think of everything. ;)
Help us help you: attach a .love.

Post Reply

Who is online

Users browsing this forum: No registered users and 77 guests