Packer is a tool for Love2D games that pack sprites into a texture atlas (or sprite sheet), which can increase game performance. This project is incomplete and currently under development.
Download the repository anywhere. You may choose to install Packer as a git submodule:
$ git submodule add [email protected]:dvdfu/packer.git modules/packer
$ git submodule init
$ git submodule update
Run the Packer folder using love
.
$ love modules/packer [source] [output]
That's all! This packs all images in source
and generates output.png
and output.lua
in your save directory. Move them to your game project.
Atlas = require 'modules/packer/atlas'
atlas = Atlas.load('output') -- load a texture atlas
playerSprite = atlas:newSprite('player.png') -- fetch a sprite from a texture atlas
coinSprite = atlas:newSprite('items/coin.png') -- this sprite was located in a subfolder
coinSprite:draw(...) -- same arguments as love.graphics.draw(image, ...)
The Atlas class represents a repository of sprites, indexed by filename. They are generated by loading an image and atlas file previously created by Packer.
Atlas.load(name)
atlas:newSprite(name)
atlas:newAnimation(name, frameCount, frameRate) -- frameRate measured in seconds
The Sprite class represents an object that is ready to be drawn by Love2D. They can be generated by retrieving a sprite from an Atlas.
sprite:getQuad()
sprite:draw(...)
An Animation is like a Sprite, but contains multiple quads that represent single frames in a looping animation. Animations should be packed as horizontal strips of equal-sized frames, much like how Aseprite exports animations.
animation:getQuads()
animation:update(dt)
animation:setFrame(frame)
Sets the frame of the animation, in the range [1, frameCount]
. Uses modulus to resolve out-of-bound frames.
animation:setFramerate(framerate)
animation:draw(...)