Documentation
¶
Overview ¶
Package pack provides texture packing utilities, including support for rotation, transparent pixel trimming, automatic resizing and so on.
Supported input image formats include PNG, JPEG, TIFF, BMP, and WEBP. Supported output formats are PNG, JPEG, TIFF, and BMP.
Index ¶
- Constants
- Variables
- func UnpackAtlas(atlasInfo *model.AtlasInfo, opts unpackedOpts) error
- func UnpackSprites(infoPath string, fn ...UnpackOpts) error
- type Algorithm
- type Heuristic
- type Options
- func (b *Options) Algorithm(algo Algorithm) *Options
- func (b *Options) AllowRotate(enable bool) *Options
- func (b *Options) AutoSize(enable bool) *Options
- func (b *Options) Heuristic(heuristic Heuristic) *Options
- func (b *Options) ImgExt(ext string) *Options
- func (b *Options) MaxSize(w, h int) *Options
- func (b *Options) Name(name string) *Options
- func (b *Options) Padding(padding int) *Options
- func (b *Options) PowerOfTwo(enable bool) *Options
- func (b *Options) SameDetect(enable bool) *Options
- func (b *Options) Sort(enable bool) *Options
- func (b *Options) Tolerance(tolerance int) *Options
- func (b *Options) Trim(enable bool) *Options
- func (b *Options) Validate() (*Options, error)
- type Packer
- type UnpackOpts
Constants ¶
const ( Repo = "https://github.com/91xusir/spritepacker" Format = "RGBA8888" )
Variables ¶
var (
Version = "dev"
)
Functions ¶
func UnpackAtlas ¶ added in v1.1.4
func UnpackSprites ¶
func UnpackSprites(infoPath string, fn ...UnpackOpts) error
Types ¶
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
func DefaultOptions ¶ added in v1.1.4
func DefaultOptions() *Options
func NewOptions ¶
func NewOptions() *Options
func (*Options) Algorithm ¶
Algorithm sets the packing algorithm of the atlas. If the algorithm is not valid, it will be set to AlgoBasic.
func (*Options) AllowRotate ¶
AllowRotate allow sprites to Rotate to optimizeAtlasSize
func (*Options) Heuristic ¶
Heuristic sets the heuristic of the atlas. If the heuristic is not valid, it will be set to BestShortSideFit. It is valid only when the algorithm is AlgoMaxRects.
func (*Options) MaxSize ¶
MaxSize sets the maximum size of the atlas. If the width or height is less than or equal to 0, it will be set to 512.
func (*Options) Name ¶
Name sets the name of the atlas. If the name is empty, the default name is "atlas".
func (*Options) Padding ¶
Padding sets the padding of the atlas. If the padding is less than 0, it will be set to 0.
func (*Options) PowerOfTwo ¶
PowerOfTwo sets the power of two of the atlas. The atlas pixels are fixed to a power of 2.
func (*Options) SameDetect ¶
SameDetect sets the same detection of the atlas.
type Packer ¶
type Packer struct {
// contains filtered or unexported fields
}
func (*Packer) PackSprites ¶
PackSprites packs the given sprite images
Parameters:
- spritePaths: the paths of the sprite images
Returns:
- *AtlasInfo: the sprite atlas info
- []image.Image: the atlas images
- error
Example:
spriteAtlas, atlasImages, err := packer.PackSprites("./input")
type UnpackOpts ¶
type UnpackOpts func(*unpackedOpts)
func WithImg ¶
func WithImg(atlasImgPath string) UnpackOpts
func WithOutput ¶
func WithOutput(outputPath string) UnpackOpts