How to limit my frames per second?

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.
Number-41
Prole
Posts: 5
Joined: Mon May 28, 2012 12:17 pm

How to limit my frames per second?

Post by Number-41 »

I tried the example code from the WIKI but when I run love.graphics.getFPS(), it halves (from ~900 to ~490). I searched for any similar threads but they provided not really an answer. I read it might be an integer multiple of 60, but then how do I get my actual fps?

Code: Select all

function love.update(dt)
	if dt <= 1/60 then
		love.timer.sleep(0.001)
	end
end
Edit:

when I simulate a point moving across the screen, it does seem to move at the right speed. So my framerate seems correct. I've heard love.run() also has some sort of framerate limiting? Will this conflict with eachother?
User avatar
richapple
Citizen
Posts: 65
Joined: Sun Dec 25, 2011 10:25 am

Re: How to limit my frames per second?

Post by richapple »

Number-41 wrote:

Code: Select all

love.timer.sleep(0.001)
eek. You shouldn't use love.timer.sleep. love.timer.sleep is for love.run

To cap FPS, simply

Code: Select all

love.update(dt)
    dt = math.min(dt, 1/60)
end
Number-41 wrote:when I simulate a point moving across the screen, it does seem to move at the right speed. So my framerate seems correct.
Did you multiply it dt? Have you tried tweaking it? If you need help you can post code snippet here.
Number-41
Prole
Posts: 5
Joined: Mon May 28, 2012 12:17 pm

Re: How to limit my frames per second?

Post by Number-41 »

So dt is not something that provides information, but rather something you force to take certain values (which the love.run() function uses to actually cap your FPS)?

Also while we're at it: how would I "add" my current view to the previous one? (so I can see traces of points drawn)
User avatar
richapple
Citizen
Posts: 65
Joined: Sun Dec 25, 2011 10:25 am

Re: How to limit my frames per second?

Post by richapple »

Number-41 wrote:So dt is not something that provides information, but rather something you force to take certain values (which the love.run() function uses to actually cap your FPS)?
dt stands for Delta Time, time passed between frames (1/FPS). By simply making it less than 1/60 will make no change. The idea is that you use it like this:

Code: Select all

function love.update(dt)
     -- capping if necessary here, mostly not necessary
     ball.x = ball.x + speed * dt
end
^ And this is where capping dt would make changes. Also, dt is always required for use on different computers, as the raw (w/o dt) perfomance would suffer.
Number-41 wrote:How would I "add" my current view to the previous one? (so I can see traces of points drawn)
Sorry, what exactly are you trying to do? Draw points on the screen or calculate something?
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: How to limit my frames per second?

Post by bartbes »

Number-41 wrote: Also while we're at it: how would I "add" my current view to the previous one? (so I can see traces of points drawn)
There's two methods to not clear the screen, the first is to actually not clear the screen, but most graphics cards do double-buffering, meaning you won't get to draw to the last frame, but the frame before that. And to make matters worse, some do triple buffering!
The reliable method would be to use a Canvas.

As for your original question, richapple was completely, and utterly wrong, his method won't affect fps in any way. love.timer.sleep is, in fact, the only way to do so (short for actually being 'slow'). A very basic formula is $$ \frac{1}{FPS_{max}} - dt $$.

By default, though, vsync is on, which generally caps the fps to 60.
User avatar
richapple
Citizen
Posts: 65
Joined: Sun Dec 25, 2011 10:25 am

Re: How to limit my frames per second?

Post by richapple »

Oopsie. I guess I'll do a double-check next time. :oops: Glad to see that my post was corrected before taken seriously.
Number-41
Prole
Posts: 5
Joined: Mon May 28, 2012 12:17 pm

Re: How to limit my frames per second?

Post by Number-41 »

If I limit it to 60, Fraps still tells me it's around 300.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: How to limit my frames per second?

Post by Nixola »

1) Use love.timer.getFPS();
2) That's not the best way, that's only the simplest; if you search in the wiki you should find the best one
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Number-41
Prole
Posts: 5
Joined: Mon May 28, 2012 12:17 pm

Re: How to limit my frames per second?

Post by Number-41 »

getFPS() tells me the same thing. I got my method from the wiki.
User avatar
tsturzl
Party member
Posts: 161
Joined: Fri Apr 08, 2011 3:24 am

Re: How to limit my frames per second?

Post by tsturzl »

using the sleep timer just idles the instructions for that duration. You should set the cap through dt, dt is a pointer that references a value from my understanding. Therefore allowing you to change its value outside your scope.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 8 guests