Hi,
I've been seraching for a bit now, but only found outdated examples for 0.8.0. What's the proper way to limit FPS in 0.9.0?
Limiting FPS in 0.9.0
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Limiting FPS in 0.9.0
Code: Select all
local t = 0
local fps = 1/30
function love.update(dt)
t=t+dt
if (t < fps) then return end
t=t%fps
print("30 times per second")
end
Re: Limiting FPS in 0.9.0
But that only makes an action happen 30 times in a second. I'd like to have proper framelimiting for everything.
Vsync in LÖVE, unfortunately, tends to drop single frames here and there.
Vsync in LÖVE, unfortunately, tends to drop single frames here and there.
Re: Limiting FPS in 0.9.0
Try this:
Code: Select all
local fps = 1/30
function love.update(dt)
if (dt < fps) then
love.timer.sleep(fps-dt)
end
end
Re: Limiting FPS in 0.9.0
love.timer.sleep((fps-dt)*2)Automatik wrote:Try this:Code: Select all
local fps = 1/30 function love.update(dt) if (dt < fps) then love.timer.sleep(fps-dt) end end
Re: Limiting FPS in 0.9.0
Thanks, it kind-of works, but it's not really what I had in mind.
Let me tell you why I need it first:
I'm doing my first proper LÖVE project I've been meaning to do since oh so long. Today I did collisions, which worked nicely. However, when I gave the game to my friend with a really crappy PC, collisions went a bit glitchy due to lower FPS. It's not really broken, but it DOES behave differently, even with proper dt usage.
So, if I limit the framerate, I can develop collisions and movement targeting that exact FPS which will behave identically on all systems. Two options there: I can use Vsync or I can use a hard framerate cap. Vsync kinda works, but people may not want it, which leaves the second option. Earlier I wrote that Vsync loses a frame or two here or there... that FPS limit example kills any semblance of smoothness, probably because love.update() isn't really the place to do it.
I saw this post back when I was searching, which looks like something I might want: http://love2d.org/forums/viewtopic.php? ... 184#p75184, however we don't have getMicroTime() anymore and I'm once again in a stump.
Let me tell you why I need it first:
I'm doing my first proper LÖVE project I've been meaning to do since oh so long. Today I did collisions, which worked nicely. However, when I gave the game to my friend with a really crappy PC, collisions went a bit glitchy due to lower FPS. It's not really broken, but it DOES behave differently, even with proper dt usage.
So, if I limit the framerate, I can develop collisions and movement targeting that exact FPS which will behave identically on all systems. Two options there: I can use Vsync or I can use a hard framerate cap. Vsync kinda works, but people may not want it, which leaves the second option. Earlier I wrote that Vsync loses a frame or two here or there... that FPS limit example kills any semblance of smoothness, probably because love.update() isn't really the place to do it.
I saw this post back when I was searching, which looks like something I might want: http://love2d.org/forums/viewtopic.php? ... 184#p75184, however we don't have getMicroTime() anymore and I'm once again in a stump.
Re: Limiting FPS in 0.9.0
Then you only need to limit the amount of times your physics update gets called and pass it a fixed dt value instead of one you get from update.aidenn wrote:I'm doing my first proper LÖVE project I've been meaning to do since oh so long. Today I did collisions, which worked nicely. However, when I gave the game to my friend with a really crappy PC, collisions went a bit glitchy due to lower FPS. It's not really broken, but it DOES behave differently, even with proper dt usage.
In other words: use the method from my first post and pass your physics update 1/30 instead of dt. That way the most the game will do when it cannot reach 30fps is run slower.
love.timer.getMicroTime() is now love.timer.getTime().aidenn wrote:I saw this post back when I was searching, which looks like something I might want: http://love2d.org/forums/viewtopic.php? ... 184#p75184, however we don't have getMicroTime() anymore and I'm once again in a stump.
Re: Limiting FPS in 0.9.0
Oooh, that explains so much. Thanks! I guess I don't need to limit FPS arbitrarily anymore. I have a question though - is it accurate? That is, can updates achieved this way synchronize perfectly with Hz 1:1?
BTW, out of curiousity I tried to test that limiter I linked with getTime() but couldn't get it to work anyway.
BTW, out of curiousity I tried to test that limiter I linked with getTime() but couldn't get it to work anyway.
Re: Limiting FPS in 0.9.0
I wouldn't rely on that.aidenn wrote:That is, can updates achieved this way synchronize perfectly with Hz 1:1?
Re: Limiting FPS in 0.9.0
That's a bummer. Any way to do clean and healthy frame-Hz relationship with LÖVE?
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 11 guests