Code: Select all
function love.run()
-- Custom fixed delta time for use in the game loop
local FRAME_DT = 1/60 -- Frame delay (in seconds)
-- Initialize game
if love.load then love.load() end
-- Game loop
local running = true
while (running) do
local frame_start = love.timer.getTime()
-- Handle events
if love.event then
love.event.pump()
for name, a,b,c,d,e,f in love.event.poll() do
if name == "quit" then
running = false
end
love.handlers[name](a,b,c,d,e,f)
end
end
-- Update game state
if love.update then love.update(FRAME_DT) end
-- Draw game state
love.graphics.clear(love.graphics.getBackgroundColor())
love.graphics.origin()
if love.draw then love.draw() end
-- Wait until its time to process the next frame
local frame_time = love.timer.getTime() - frame_start
if (frame_time < FRAME_DT) then
love.timer.sleep(FRAME_DT - frame_time)
end
-- Flip backbuffer
love.graphics.present()
end
end