I see this: https://love2d.org/wiki/love.timer.getTime
So I could technically just start a timer and never finish it.
Basically need a timer that returns some fraction of a second identical to SDL_GetTicks.
Also a problem SDL_GetTicks has, is it overflows at 49 days, but you can get around that using modular arithmetic such as ""end - start >= interval". Is this issue the same in love2d?
SDL_GetTicks equivalent in love?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: SDL_GetTicks equivalent in love?
Not sure what you mean by "start a timer". LÖVE only has global time, no timers that can be started or stopped.
getTime returns the time in seconds that has elapsed since some unspecified starting time. It should do what you ask for. You can also keep track of time in love.update(dt), where dt is the time in seconds since the last frame.
The overflow after 49.71 days happens because a 32 bit unsigned integer counting milliseconds will overflow after that time. LÖVE does not use that, and AFAIK overflows will not happen (within a reasonable time frame).
getTime returns the time in seconds that has elapsed since some unspecified starting time. It should do what you ask for. You can also keep track of time in love.update(dt), where dt is the time in seconds since the last frame.
The overflow after 49.71 days happens because a 32 bit unsigned integer counting milliseconds will overflow after that time. LÖVE does not use that, and AFAIK overflows will not happen (within a reasonable time frame).
Re: SDL_GetTicks equivalent in love?
> since some unspecified starting timegrump wrote: ↑Wed Oct 24, 2018 5:12 am Not sure what you mean by "start a timer". LÖVE only has global time, no timers that can be started or stopped.
getTime returns the time in seconds that has elapsed since some unspecified starting time. It should do what you ask for. You can also keep track of time in love.update(dt), where dt is the time in seconds since the last frame.
The overflow after 49.71 days happens because a 32 bit unsigned integer counting milliseconds will overflow after that time. LÖVE does not use that, and AFAIK overflows will not happen (within a reasonable time frame).
Can you give more context about this?
dt doesn't seem to accurate, but I could add that to a variable to get a semblance of getTicks
getTime returns in seconds, but I would need in milliseconds or something much smaller. GetTicks returns a small enough number that can do color shifting or animations using it.
Re: SDL_GetTicks equivalent in love?
It has an unspecified value when you start your game, it doesn't start at 0.
It returns seconds, but that is not the resolution of the timer, which is much higher (down to microseconds). Just multiply with 1000 to get milliseconds. Note that you don't work with ints in Lua, all numbers are 64 bit floating point values.getTime returns in seconds, but I would need in milliseconds or something much smaller. GetTicks returns a small enough number that can do color shifting or animations using it.
- zorg
- Party member
- Posts: 3469
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: SDL_GetTicks equivalent in love?
If you do need an SDL_GetTicks like function then here's one way to do it:
But again, i don't know the internals of the clock being used, so this may also suffer from the occasional (but very rare) overflow issue you mentioned; Then again, if you want to play timekeeping on the scale of months, i'd suggest completely separating the date portion from the time portion altogether; it's more sane to do so anyway.
Code: Select all
-- Put this in love.load (or at the top of main.lua or whatever)
initTimeOffset = love.timer.getTime()
function getTicks()
-- accurate exactly to milliseconds.
return math.floor((love.timer.getTime() - initTimeOffset) * 1000)
end
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Who is online
Users browsing this forum: Ahrefs [Bot] and 7 guests