Page 1 of 1
Set FPS
Posted: Tue Jun 02, 2015 4:12 am
by Ortimh
Just simple, how to set FPS? Does it possible?
Re: Set FPS
Posted: Tue Jun 02, 2015 4:24 am
by ivan
Ortimh wrote:Just simple, how to set FPS? Does it possible?
Not really. Let's say you set it to 60 (1/60 of a second) per frame.
But the "love.update" step could take 2/60 or longer depending on your Lua code.
Or your CPU might be busy with some other process.
In general, you can't expect a constant FPS that's why we have "love.update(delta)".
On the other hand updating your game with a "fixed" time step is possible.
The basic idea is to execute several "steps" per frame if there is any lag:
Code: Select all
accum = 0
step = 0.016 -- fixed time step
function updateGameLogic(dt)
accum = accum + dt
while accum >= step do
-- process player input here
-- update the game logic/simulation
accum = accum - step
end
end
PS.This is for illustrative purposes. In practice, you want to limit/clamp the number of 'steps' per update when using a fixed time step.
Re: Set FPS
Posted: Tue Jun 02, 2015 5:24 am
by BlueWolf
Sure you can have fixed 60 fps. You just have to make sure you update/draw for one frame takes always less than 16.666... miliseconds. If you can achieve that you can have fixed 60 fps.
Also delta is always lagging one frame behind, so it works best with semi consistent framerates (i.e. your update not spiking from 5 - 40 ms on frame by frame basis). Whether anyone would notice that is questionable. I would say you can't possibly see that one frame lag however much the framerate is spiking. But... if you want to be completely technically correct in what you're showing on the screen you have to use fixed framerate. As I said though no one will probably notice so why bother?
Re: Set FPS
Posted: Tue Jun 02, 2015 6:36 am
by Ortimh
Thanks for the detailed replies. I'm sorry but I just need a yes or no kind of answers. If yes then how to do it. If no then.. no.
I'm trying to implement the solution of my question by:
Code: Select all
function love.load(arg)
time = 0
fps = 30
end
function love.update(dt)
time = time + dt
if (time >= 1 / fps) then
-- update the game
end
end
Re: Set FPS
Posted: Tue Jun 02, 2015 9:58 am
by kikito
Ortimh wrote:Thanks for the detailed replies. I'm sorry but I just need a yes or no kind of answers. If yes then how to do it. If no then.. no.
No.
Re: Set FPS
Posted: Tue Jun 02, 2015 10:09 am
by ivan
BlueWolf wrote:Sure you can have fixed 60 fps. You just have to make sure you update/draw for one frame takes always less than 16.666... miliseconds. If you can achieve that you can have fixed 60 fps.
Yes, you're right to some extent.
But don't forget that the Love2D application itself can lag, especially on slower PC's and when I/O is involved.
So there is no reliable way to guarantee an "ideal" delta value.
The fixed step approach using accumulators is very good in my experience, especially when physics and more advanced simulation is involved.
Re: Set FPS
Posted: Tue Jun 02, 2015 12:21 pm
by zorg
Ortimh wrote:Thanks for the detailed replies. I'm sorry but I just need a yes or no kind of answer. If yes then how to do it. If no then.. no.
I highlighted the illogical parts; basically you want yes or no, but if it's yes, then you want a detailed answer; seems to me that that's exactly what you got. I'll choose not to interpret the message as hostile.
As for your code, it can work, though you should just have the 1/fps value stored in love.load, instead of dividing it every frame; a minor thing, but it's still faster that way

(though the code others posted are more robust)
Re: Set FPS
Posted: Wed Jun 03, 2015 4:08 am
by Ortimh
Thanks for the highlight. Sorry then. And I agree with you instead of dividing 1 / fps I should store it in a variable.
Re: Set FPS
Posted: Wed Jun 03, 2015 11:14 am
by bartbes
Ortimh wrote:instead of dividing 1 / fps I should store it in a variable.
Conveniently, this is the value of [wiki]love.timer.getAverageDelta[/wiki].
Re: Set FPS
Posted: Fri Jun 05, 2015 6:35 am
by Ortimh
Ah, didn't notice that. Thanks, bartbes