Roomshift

January 18, 2026 · View on GitHub

Room-based camera with smooth transitions for LÖVE.

Demo

Features

  • Smooth camera panning between rooms
  • Automatic viewport clamping to room boundaries
  • Centers camera on rooms smaller than the viewport
  • Configurable follow axes (horizontal, vertical, or both)
  • Simple API with no dependencies beyond LÖVE

Installation

Copy roomshift.lua into your project and require it:

local Roomshift = require("roomshift")

Quick Start

local Roomshift = require("roomshift")

local camera
local player = { x = 100, y = 100, width = 16, height = 16 }
local room = Roomshift.newRoom(0, 0, 800, 480)

function love.load()
    camera = Roomshift.newCamera(400, 240, 480, "both")
end

function love.update(dt)
    camera:follow(player, room, dt)
    camera:update(dt)
end

function love.draw()
    camera:apply()
    -- Draw your world here
    love.graphics.rectangle("fill", player.x, player.y, player.width, player.height)
    camera:reset()
end

API Reference

Roomshift.newCamera(viewportWidth, viewportHeight, panSpeed, followAxes)

Creates a new camera instance.

ParameterTypeDescription
viewportWidthnumberWidth of the viewport in pixels
viewportHeightnumberHeight of the viewport in pixels
panSpeednumberSpeed of room transitions in pixels per second
followAxesstring"horizontal", "vertical", or "both"

Roomshift.newRoom(x, y, width, height)

Creates a room table. Helper function for convenience.

ParameterTypeDescription
xnumberLeft edge of the room in pixels
ynumberTop edge of the room in pixels
widthnumberWidth of the room in pixels
heightnumberHeight of the room in pixels

Returns a table with { x, y, width, height }.

camera:follow(target, room, dt)

Follows a target within a room, respecting room boundaries. Call every frame.

ParameterTypeDescription
targettableMust have x, y, width, height properties
roomtableMust have x, y, width, height properties
dtnumberDelta time (unused, kept for API consistency)

camera:update(dt)

Updates camera position during room transitions. Call every frame.

camera:apply()

Applies the camera transformation. Call before drawing world objects.

camera:reset()

Resets the camera transformation. Call after drawing world objects.

camera:getZoom()

Returns the current zoom level.

camera:getClampedPosition(x, y, room)

Returns a position clamped to room boundaries. Useful for initial camera positioning.

camera:clampToRoom(room)

Clamps the camera's current position to the given room boundaries.

camera:startRoomTransition(newRoom)

Manually starts a smooth transition to a new room.

Room Format

A room is any table with these properties:

{
    x = 0,        -- left edge in pixels
    y = 0,        -- top edge in pixels
    width = 800,  -- room width in pixels
    height = 480  -- room height in pixels
}

You can use Roomshift.newRoom() or create tables yourself. Rooms can come from Tiled, be hardcoded, or generated procedurally.

License

MIT License. See LICENSE for details.