How to limit my frames per second?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: How to limit my frames per second?
You do NOT have to change DT, unless you know what you're doing, changing DT will not change the framerate. The wiki has also a more complex snip that caps more accurately
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Re: How to limit my frames per second?
I don't want to cap accurately (if that means a matter of 5 or 6 fps), I just want a clear way on how to reduce it to around 50. Which none of the above methods (or the one on the wiki) do (though thanks for the quick replies ).
Also the wiki says that it doesn't support that function anymore in 8.0.
Also the wiki says that it doesn't support that function anymore in 8.0.
Last edited by Number-41 on Mon May 28, 2012 8:51 pm, edited 1 time in total.
- slime
- Solid Snayke
- Posts: 3163
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: How to limit my frames per second?
Here's my love.run. It works decently, although I get stuttering at <= 60 max fps, but I'm not sure what to do about it.
Code: Select all
function love.run()
love.load(arg)
local dt = 0
while true do
local frametimestart = love.timer.getMicroTime()
love.event.pump()
for e,a,b,c,d in love.event.poll() do
if e == "quit" then
if not love.quit or not love.quit() then
if love.audio then
love.audio.stop()
end
return
end
end
love.handlers[e](a,b,c,d)
end
love.timer.step()
dt = love.timer.getDelta()
love.update(dt)
love.graphics.clear()
love.draw()
love.graphics.present()
local frametimeend = love.timer.getMicroTime()
local framedelta = frametimeend - frametimestart
if maxfps and maxfps > 0 then -- 0 is unlimited
local max_dt = 1/maxfps
local sleeptime = max_dt - framedelta
if sleeptime >= 0.001 then -- love will truncate anything less than 1ms down to 0 internally
love.timer.sleep(sleeptime)
end
else
love.timer.sleep(0.001)
end
end
end
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: How to limit my frames per second?
That is all kinds of wrong.tsturzl wrote: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.
Maybe it works better if you provide an upper limit for sleeptime.slime wrote:Here's my love.run. It works decently, although I get stuttering at <= 60 max fps, but I'm not sure what to do about it.
Help us help you: attach a .love.
Re: How to limit my frames per second?
If nothing changes during a love.update, then whatever your draw in the next love.draw will be identical to the previous frame. In that regard, you accumulate up enough love.update calls and then react when enough has been called to fit your desired framerate. For instance:
Code: Select all
dt_buffer = 0
desired = 1/60
function love.update(dt)
dt_buffer = dt_buffer + dt
if dt_buffer > desired then
dt_buffer = dt_buffer - desired
updateWorld()
end
end
Who is online
Users browsing this forum: Ahrefs [Bot] and 8 guests