Page 1 of 2

How to limit my frames per second?

Posted: Mon May 28, 2012 12:26 pm
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?

Re: How to limit my frames per second?

Posted: Mon May 28, 2012 2:48 pm
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.

Re: How to limit my frames per second?

Posted: Mon May 28, 2012 2:54 pm
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)

Re: How to limit my frames per second?

Posted: Mon May 28, 2012 3:51 pm
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?

Re: How to limit my frames per second?

Posted: Mon May 28, 2012 4:01 pm
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.

Re: How to limit my frames per second?

Posted: Mon May 28, 2012 4:10 pm
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.

Re: How to limit my frames per second?

Posted: Mon May 28, 2012 4:47 pm
by Number-41
If I limit it to 60, Fraps still tells me it's around 300.

Re: How to limit my frames per second?

Posted: Mon May 28, 2012 6:17 pm
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

Re: How to limit my frames per second?

Posted: Mon May 28, 2012 6:38 pm
by Number-41
getFPS() tells me the same thing. I got my method from the wiki.

Re: How to limit my frames per second?

Posted: Mon May 28, 2012 6:53 pm
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.