How can i combat this?
pseudo code example of what i want to achieve:
Code: Select all
if not love.window.isMoving() then
love:update()
end
Code: Select all
if not love.window.isMoving() then
love:update()
end
Code: Select all
function love.update(dt)
if dt >= 1 then
return
end
--Your normal update code here--
end
Code: Select all
function love.load()
ACCUMULATED_DELTA_TIME = 0
end
function love.update(dt)
ACCUMULATED_DELTA_TIME = ACCUMULATED_DELTA_TIME + dt
if ACCUMULATED_DELTA_TIME > 0.016666 then -- approx 1 / 60
ACCUMULATED_DELTA_TIME = 0
-- run stuffs
end
end
Code: Select all
function love.load()
ACCUMULATED_DELTA_TIME = 0
MAX_UPDATE_LOOPS = 3
end
function love.update(dt)
ACCUMULATED_DELTA_TIME = ACCUMULATED_DELTA_TIME + dt
local num_update_loops = 0
while ACCUMULATED_DELTA_TIME > 0.016666 and num_update_loops < MAX_UPDATE_LOOPS do -- approx 1 / 60
ACCUMULATED_DELTA_TIME = ACCUMULATED_DELTA_TIME - 0.016666
num_update_loops = num_update_loops + 1
-- run stuffs
end
end
Thanks for the suggestions all, i've gone with s-ol's as it seems more simple.s-ol wrote:Usually this happens because the window is not being updated while you drag it, and as a result the dt is very high after it is dropped. Try putting dt = math.min(dt, 1/30) at the top of love.update and see if that fixes it / whether thats whats going on.
Code: Select all
dt = math.min(dt, 1/max_fps)
Code: Select all
function love.load()
max_fps = 120
min_dt = 1/max_fps
next_time = love.timer.getTime()
end
function love.update(dt)
dt = math.min(dt, min_dt)
next_time = next_time + min_dt
--[[ update code
--]]
end
function love.draw()
--[[ draw code
--]]
local cur_time = love.timer.getTime()
if next_time <= cur_time then
next_time = cur_time
return
end
love.timer.sleep(next_time - cur_time)
end
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 5 guests