
# Projection

Converts world coordinates into the [2D canvas](canvas.md) coordinate space. Call it from a
render callback: `render_2d`, `render_gui` or `frame`.

| Function | Returns |
|----------|---------|
| `projection.to_screen(pos[, ignore_frustum])` | Screen `sx, sy`, or `nil` behind the camera or out of view |
| `projection.box(min, max)` | Box on screen as `x, y, w, h`, or `nil` |
| `projection.entity_box(entity_id)` | Interpolated entity hitbox as `x, y, w, h`, or `nil` |

`ignore_frustum = true` also projects points outside the view and fails only behind the
camera, which is what edge-of-screen indicators need.

```lua
module:event("render_2d", function(render)
    for _, p in ipairs(world:players()) do
        if not p:is_self() then
            local x, y, w, h = projection.entity_box(p:id())
            if x then
                render.rect(x, y, w, h, render.paint(0xFF4FF2A6):stroke(1, "inside"))
            end
        end
    end
end)
```
