Home › LÖVE (Love2D) › LÖVE (Love2D) Lua game rules
LÖVE (Love2D) Lua game rules
Cursor rules for 2D games with LÖVE 11.5 in Lua: callbacks, modules, delta time, asset loading, and performance.
CursorLÖVE (Love2D)
How to use
Save this as .cursor/rules/love2d.mdc in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.
.cursor/rules/love2d.mdcDownload ---
description: LÖVE (Love2D) Lua game conventions
globs: ["**/*.lua"]
alwaysApply: false
---
# LÖVE (Love2D 11.5)
- `main.lua` only defines `love.load`, `love.update(dt)`, `love.draw`, and input callbacks, delegating to a scene/state manager in `src/`.
- Modules return a table: `local Player = {}; Player.__index = Player; function Player.new(x, y) ... end; return Player`. Everything `local`; no accidental globals (enable a strict mode or run `luacheck`).
- Multiply all movement and timers by `dt`. Use a fixed-step accumulator for physics-sensitive logic.
- Load images, fonts, sounds, and shaders once in `love.load` or a scene's `enter` and cache them in an `assets` module. Never call `love.graphics.newImage`/`newFont` inside `update`/`draw`.
- Pixel art: `love.graphics.setDefaultFilter("nearest", "nearest")` before loading images; draw to a canvas at native resolution and scale it.
- Batch many identical sprites with `SpriteBatch` and texture atlases (`Quad`s).
- Reset graphics state you change (`love.graphics.push()`/`pop()`, `setColor(1,1,1,1)`). Colors are 0-1, not 0-255.
- Use `love.physics` (Box2D) only when real physics is needed; otherwise simple AABB checks.
- Save data with `love.filesystem` (writes to the save directory), serialized as JSON or Lua tables.
- Configure window and modules in `conf.lua`.
## Done when
`luacheck src main.lua` reports no warnings and the game runs with `love .` without errors in the console.