Appearance
LOVE exporter
How it works
Packrat writes one Lua module and the image files for all atlas pages. The module contains frame metadata, animation frame lists, loaded Image objects, and Quad objects. Its draw helpers reconstruct trimmed frames, so game code works with a frame object instead of atlas coordinates.
API
The generated module exposes a Lua definition table with these fields:
text
definition = {
version = 2, -- number
pages = {
{ image = "string", width = number, height = number }
},
frames = {
{
key = "string", name = "string", page = number,
x = number, y = number, width = number, height = number,
rotated = boolean, trimmed = boolean,
source_x = number, source_y = number,
source_width = number, source_height = number,
index = number
}
},
animations = {
{ name = "string", frames = { "frame-key", ... } }
}
}page is one-based in the Lua table. source_x and source_y are the top-left trim offset; index is the source animation index, or -1 for a static frame. The module returns an Atlas object with these methods:
text
Atlas:load(): Atlas
Atlas:unload(): Atlas
Atlas:set_filter(min_filter: string, mag_filter: string|nil): Atlas
Atlas:frame(name: string, index: number|nil): Frame|nil
Atlas:find_animation(name: string): Animation|nil
Atlas:draw(
frame_value: Frame|string,
x: number|nil, y: number|nil,
rotation: number|nil,
scale_x: number|nil,
scale_y: number|nil): nil
Atlas:add(
batch: SpriteBatch,
frame_value: Frame|string,
x: number|nil, y: number|nil,
rotation: number|nil,
scale_x: number|nil,
scale_y: number|nil): numberframe accepts either a full key or a base animation name; a missing or negative index returns the first match. Optional draw values default to x = 0, y = 0, rotation = 0, scale_x = 1, and scale_y = scale_x. load creates the LOVE Image and Quad objects; unload releases them.
Integrate
Keep the generated module and image files together under the LOVE project root. The module loads images on demand and exposes the animation frames:
lua
local atlas = require("atlas")
local animation
local frame_index = 1
local timer = 0
function love.load()
atlas:set_filter("nearest", "nearest")
atlas:load()
animation = atlas:find_animation("run_side")
end
function love.update(dt)
timer = timer + dt
if timer >= 0.1 then
timer = timer - 0.1
frame_index = frame_index % #animation.frames + 1
end
end
function love.draw()
atlas:draw(animation.frames[frame_index], 400, 300, 0, 2, 2)
end
function love.quit()
atlas:unload()
endatlas.definition contains the page list, frame records, and animation records when direct metadata access is needed. Use the image extension selected for the export in generated page paths.