Limiting FPS in 0.9.0

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.
aidenn
Prole
Posts: 15
Joined: Wed Feb 12, 2014 6:13 pm

Limiting FPS in 0.9.0

Post by aidenn »

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?
User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Re: Limiting FPS in 0.9.0

Post by Azhukar »

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
You can also turn on vsync in conf.lua.
aidenn
Prole
Posts: 15
Joined: Wed Feb 12, 2014 6:13 pm

Re: Limiting FPS in 0.9.0

Post by aidenn »

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.
Automatik
Citizen
Posts: 57
Joined: Sun Feb 17, 2013 7:05 pm

Re: Limiting FPS in 0.9.0

Post by Automatik »

Try this:

Code: Select all

local fps = 1/30
function love.update(dt)
   if (dt < fps) then
       love.timer.sleep(fps-dt)
   end
end
User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Re: Limiting FPS in 0.9.0

Post by Azhukar »

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
love.timer.sleep((fps-dt)*2)
aidenn
Prole
Posts: 15
Joined: Wed Feb 12, 2014 6:13 pm

Re: Limiting FPS in 0.9.0

Post by aidenn »

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.
User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Re: Limiting FPS in 0.9.0

Post by Azhukar »

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.
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.

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.
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.
love.timer.getMicroTime() is now love.timer.getTime().
aidenn
Prole
Posts: 15
Joined: Wed Feb 12, 2014 6:13 pm

Re: Limiting FPS in 0.9.0

Post by aidenn »

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.
User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Re: Limiting FPS in 0.9.0

Post by Azhukar »

aidenn wrote:That is, can updates achieved this way synchronize perfectly with Hz 1:1?
I wouldn't rely on that.
aidenn
Prole
Posts: 15
Joined: Wed Feb 12, 2014 6:13 pm

Re: Limiting FPS in 0.9.0

Post by aidenn »

That's a bummer. Any way to do clean and healthy frame-Hz relationship with LÖVE?
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 11 guests