Set FPS
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Set FPS
Not really. Let's say you set it to 60 (1/60 of a second) per frame.Ortimh wrote:Just simple, how to set FPS? Does it possible?
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
Re: Set FPS
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?
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
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:
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
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: Set FPS
No.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.
When I write def I mean function.
Re: Set FPS
Yes, you're right to some extent.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.
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.
- zorg
- Party member
- Posts: 3477
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Set FPS
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.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.
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

Me and my stuff
True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.

Re: Set FPS
Thanks for the highlight. Sorry then. And I agree with you instead of dividing 1 / fps I should store it in a variable.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Set FPS
Conveniently, this is the value of [wiki]love.timer.getAverageDelta[/wiki].Ortimh wrote:instead of dividing 1 / fps I should store it in a variable.
Re: Set FPS
Ah, didn't notice that. Thanks, bartbes
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 3 guests