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

Re: Best way to do a timer?

Post by kikito »

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
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Best way to do a timer?

Post by Robin »

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: Bing [Bot], Kakkassery_Joseph and 202 guests