LU

LOVE2D

Building 2D games with LOVE2D: game loop, rendering, physics, and asset management

Details

Language / Topic
luaLua
Category
framework
Compatible Frameworks
love2d

Rules

balanced
- Implement the three core callbacks: `love.load()` for initialization, `love.update(dt)` for logic, and `love.draw()` for rendering — never mix logic into `love.draw()`.
- Use `dt` (delta time) from `love.update(dt)` for all movement and timer calculations — never use `love.timer.getTime()` for per-frame deltas.
- Load assets once in `love.load()` with `love.graphics.newImage('path/file.png')` — never load files inside `love.update` or `love.draw`.
- Use `love.graphics.push()` and `love.graphics.pop()` to isolate transformation state (translate, rotate, scale) per entity draw call.
- Structure game state with a state machine — switch between `menu`, `playing`, and `gameover` states by swapping the active `update`/`draw` function pair.
- Use `love.physics` (Box2D wrapper) for physics simulation — create `World`, `Body`, `Shape`, and `Fixture` objects and step with `world:update(dt)`.
- Use `love.audio.newSource('file.ogg', 'stream')` for music and `'static'` for short sound effects — stream large files to avoid memory spikes.