Skip to content

unitoftime/packer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Packer

This is a work in progress texture packing standalone. Right now the packing algorithm isn't very optimized in terms of speed, but probably finds a fairly well packed set of images.

Install

go install github.com/unitoftime/packer/cmd/packer@latest

Note: the binary is held in cmd/packer/ so the suffix /... is required to install the packer binary to your go path.

Usage

Basic

packer --input sprites --output ./path/to/file

Flags

--input <Directory> - The directory of the input folder
--output <Filename> - The filename of the output json and png files
--extrude <Value> - The amount to extrude each sprite
--stats - If true, display statistics
--size <Value> - The width and height of the packed atlas

Serialized Json

The JSON file created by the packer binary is of form SerializedSpritesheet. (See packer.go for reference):

type SerializedRect struct {
	X,Y,W,H float64
}
type SerializedPos struct {
	X,Y float64
}
type SerializedDim struct {
	W,H float64
}

type SerializedFrame struct {
	Frame SerializedRect
	Rotated bool
	Trimmed bool
	SpriteSourceSize SerializedRect
	SourceSize SerializedDim
	Pivot SerializedPos
}
type SerializedSpritesheet struct {
	ImageName string
	Frames map[string]SerializedFrame
	Meta map[string]interface{}
}

Example Output

You can go to the packer/cmd/images/ and use the generate.sh script to generate some random images. Then you can rerun the test.

packed

Remaining Work

  • Create package to let developers dynamically pack images (ie not through command line)
  • Dynamically resize atlas image (rather than using a size flag)
  • Optimize

About

Super basic sprite packing library

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published