0Pricing
Lua Academy · Lesson

The LOVE Game Loop

load, update, and draw.

The LOVE Game Loop is a free Lua Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Lua Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

What Is LÖVE?

LÖVE (also written love2d) is a free framework that lets you build 2D games in pure Lua. You write callback functions and the engine calls them for you.

A LÖVE game lives in a folder with a main.lua file. You run it with love . from that folder, and the engine boots a window and starts the loop.

The Three Core Callbacks

LÖVE drives your game through three callbacks you define in main.lua: love.load, love.update, and love.draw.

You do not call them yourself. The engine calls love.load once, then repeats love.update and love.draw every frame for as long as the game runs.

function love.load() end
function love.update(dt) end
function love.draw() end

love.load: One-Time Setup

love.load runs exactly once when the game starts. Use it to set up state: load images and fonts, create your tables, and initialize variables before the loop begins.

Anything expensive should happen here, not inside love.update or love.draw, so it does not repeat every frame.

function love.load()
  player = { x = 100, y = 100, speed = 200 }
  score = 0
end

love.update: Game Logic

love.update(dt) runs once per frame and holds your game logic: moving objects, checking collisions, updating timers, and reading input state.

The dt argument is delta time, the seconds elapsed since the last frame. You should never draw inside update; keep drawing in love.draw.

function love.update(dt)
  player.x = player.x + player.speed * dt
end

Why dt Matters

Frame rate varies between machines. If you moved by a fixed amount each frame, a fast computer would move objects quicker than a slow one.

Multiplying by dt makes motion frame-rate independent. speed * dt means "speed units per second", so an object travels the same distance regardless of how many frames render.

-- 200 pixels per second, on any machine
player.x = player.x + 200 * dt

love.draw: Rendering

love.draw runs once per frame after love.update. Everything you see on screen is drawn here using the love.graphics module.

The screen is cleared automatically before each draw call, so you redraw the full scene every frame from your current game state.

function love.draw()
  love.graphics.rectangle('fill', player.x, player.y, 32, 32)
end

The Full Loop Together

Put the callbacks together and you have a complete game: load sets up the player, update moves it using dt, and draw renders it.

This load-update-draw cycle is the heartbeat of every LÖVE game, no matter how complex it becomes.

function love.load() x = 0 end
function love.update(dt) x = x + 100 * dt end
function love.draw()
  love.graphics.circle('fill', x, 150, 20)
end

Reading the Clock

Accumulate dt to build timers. A common pattern is summing elapsed time and acting when it crosses a threshold, then subtracting the threshold back off.

This is more reliable than counting frames, since frame counts depend on hardware while dt tracks real seconds.

timer = 0
function love.update(dt)
  timer = timer + dt
  if timer >= 1 then
    score = score + 1
    timer = timer - 1
  end
end

love.run and the Loop Internals

Behind the scenes, love.run is the actual main loop. It calls love.load once, then loops forever: it processes events, computes dt, calls your update and draw, and presents the frame.

You rarely override love.run, but knowing it exists explains where dt and the callbacks come from.

-- simplified idea of love.run
-- love.load()
-- while true do
--   dt = timer.step()
--   love.update(dt)
--   love.draw()
-- end

love.quit and Lifecycle

LÖVE also offers lifecycle callbacks beyond the core three. love.quit fires when the player closes the window, letting you save progress.

Returning true from love.quit cancels the close. Other callbacks like love.focus and love.resize respond to window events.

function love.quit()
  print('Saving before exit...')
  return false  -- false lets the game close
end

Pausing the Game

Because love.update drives all logic, pausing is easy: guard your logic behind a flag and skip it when paused.

Drawing still runs, so you can render a pause overlay. This separation of update from draw is exactly why the loop design is so flexible.

paused = false
function love.update(dt)
  if paused then return end
  player.x = player.x + player.speed * dt
end

Quick Check

Test your understanding of the LÖVE game loop.

Recap

LÖVE runs your game through callbacks: love.load sets up once, love.update(dt) handles logic every frame, and love.draw renders every frame.

The dt value keeps motion frame-rate independent, and lifecycle callbacks like love.quit round out the loop. This cycle powers every love2d game.

Frequently asked questions

Is the “The LOVE Game Loop” lesson free?

Yes — the full text of “The LOVE Game Loop” is free to read here on the web, and the Lua Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Lua Academy course, upgrade to CoddyKit PRO.

What will I learn in “The LOVE Game Loop”?

load, update, and draw. You practise Lua Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Lua Academy?

No prior experience is required. Lua Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “The LOVE Game Loop” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Lua Academy lesson?

Yes. Every Lua Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. The LOVE Game Loop
  2. Drawing Shapes and Images
  3. Handling Input
  4. Movement and Collisions
← Back to Lua Academy