pckr

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2021 License: MIT Imports: 4 Imported by: 0

README

pckr

Texture Packing library for Ebiten. Packs multiple textures into a single image on-the-fly.

GoDoc

Simple Example

func (g *Game) setup() {

	// create a new packer
	packer := pckr.NewPacker(1024, 1024)

	// add images to the packer
	packer.Add("priest", ebiten.NewImageFromImage(bytes2Image(&images.CHARACTER_HERO_PRIEST)), 0, 0, 600, 300)
	packer.Add("archor", ebiten.NewImageFromImage(bytes2Image(&images.CHARACTER_HERO_ARCHOR)), 0, 0, 600, 300)
	packer.Add("warrior", ebiten.NewImageFromImage(bytes2Image(&images.CHARACTER_HERO_WARRIOR)), 0, 0, 600, 300)

	// execute texture packing
	packer.Pack()

	packedImage := packer.Image()
	packedLocation := packer.Location("archor")

	// ...
}

Result

image

source code

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Algo

type Algo interface {
	Pack(R []*Rectangle, maxWidth, maxHeight int)
}

Algo represents an algorithm for Rectangle Packing

type Packer

type Packer struct {
	// contains filtered or unexported fields
}

Packer packs multiple images into a single image for performance reasons

func NewPacker

func NewPacker(w, h int) *Packer

NewPacker creates a new packer

func (*Packer) Add

func (p *Packer) Add(id string, img *ebiten.Image, x0, y0, x1, y1 int)

Add adds img for packing

func (*Packer) Image

func (p *Packer) Image() *ebiten.Image

Image returns the packedImage

func (*Packer) Location

func (p *Packer) Location(id string) *image.Rectangle

Location returns the location of the image packed into

func (*Packer) Pack

func (p *Packer) Pack()

Pack execute packing

func (*Packer) SetAlgo

func (p *Packer) SetAlgo(algo Algo)

SetAlgo sets algo for rectangle packing

type Rectangle

type Rectangle struct {
	W, H, X, Y int
}

Rectangle represents a rectangle area

func Rect

func Rect(w, h int) Rectangle

Rect returns a Rectangle object

type SimpleAlgo

type SimpleAlgo struct{}

SimpleAlgo is a simple but fast algorithm

func (SimpleAlgo) Pack

func (pckr SimpleAlgo) Pack(R []*Rectangle, maxWidth, maxHeight int)

Pack computes the locations for the rectangles

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL