elloramir / packer

2d binary packing for love2d

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

explanation and methods

  • packer have a method called sort that can be overrided, but i recommend to keep as default (max side)
  • after genAtlas exec, packer.atlas will be a canvas
  • save methods use lua io.open as default, if are necessary to change it, you can replace these functions
function param return
add image: Image, tag: string (optional)
genAtlas
getRect tag: string x: int, y: int, w: int, h: int
getQuad tag: string quad: Quad
serialize serial: string
saveAtlas path: string error: error
saveSerial path: string error: error

code example

local packer = require "packer"

function love.load()
	local files = love.filesystem.getDirectoryItems("test_images/")

	for _, file in ipairs(files) do
		local fileName = "test_images/" .. file

		packer:add(love.graphics.newImage(fileName), fileName)
	end

	packer:genAtlas()
	packer:saveAtlas("atlas.png")
	packer:saveSerial("serial.lua")
end

function love.draw()
	love.graphics.draw(packer.atlas, 0, 0)
end

credits

About

2d binary packing for love2d

License:MIT License


Languages

Language:Lua 100.0%