LÖVE (Love2D) Core
Set up and debug the foundation of a LÖVE game in Lua: the callback loop, frame-rate- independent movement, input, and screen states. Targets LÖVE 11.5.
When to use
- Use when starting a LÖVE game, wiring up
main.lua/conf.lua, or fixing the core loop, movement that runs at the wrong speed, input handling, or screen switching. - Use when the workspace has
main.luacallinglove.*, aconf.lua, or a.lovefile.
When not to use: Lua language questions unrelated to LÖVE; physics bodies/joints
(LÖVE uses Box2D via love.physics — a separate concern); shader code (love.graphics
GLSL is its own topic). For cross-engine save/load patterns, use save-systems.
Core workflow
- Confirm the entry points. A LÖVE game runs
main.lua; it should definelove.load()(one-time setup),love.update(dt)(state), andlove.draw()(rendering). Window/version setup goes inconf.lua(run before modules load). - Pin the version. Set
t.version = "11.5"inconf.luaso LÖVE warns on mismatch. - Drive all motion by
dt(delta time, in seconds) so speed is frame-rate independent. - Handle input two ways: polled (
love.keyboard.isDowninupdate, for held keys) and event (love.keypressedcallback, for discrete presses). - Manage screens (menu, game, pause) with a small state stack rather than a pile of
ifflags — see Patterns andreferences/state-stack.md. - Run and observe. Launch with
love .from the project folder; verify the window, motion speed, and input on screen before assuming it works.
Patterns
1. main.lua skeleton (the callback loop + input)
2. Frame-rate independence (the single most common bug)
3. conf.lua (window + version; runs before main.lua)
4. Color is 0–1 in LÖVE 11.x (not 0–255)
5. Screen states (brief — full manager in references)
Pitfalls
- Speed varies with FPS → you forgot
* dt. Every per-frame change to position, timers, or animation must be scaled bydt. love.confplaced inmain.lua→ it silently does nothing. It must live inconf.lua, which LÖVE runs before loading modules.- Colors washed out or invisible → you used 0–255 values. In 11.x,
setColor(255,0,0)clamps to white; usesetColor(1,0,0)orlove.math.colorFromBytes. - Everything tinted after one
setColor→ color is global and persists across draws. Reset withlove.graphics.setColor(1, 1, 1)before drawing text/images you want untinted. - Nothing happens on key release/repeat →
love.keypressed(key, scancode, isrepeat)fires on press (and OS key-repeat); uselove.keyreleasedfor release, and checkisrepeatif you must ignore held-key repeats.
References
- For a complete push/pop screen-state manager (menu → game → pause, with delegated
callbacks), read
references/state-stack.md.
Related skills
save-systems— saving/loading game state (engine-agnostic).input-systems— rebindable, multi-device input architecture.pygame-core/phaser-core— the same loop concepts in other lightweight engines.


