atlas

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2021 License: MIT Imports: 4 Imported by: 0

README

atlas

This library can be used to create (not read) images atlases. That is, combine multiple images into one. This is useful in games with many small textures. Having one large texture and addressing sub-rectangles in it is more efficient than having many small textures and swapping between them.

See the documentation for an API overview.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Atlas

type Atlas struct {
	draw.Image
	SubImages []SubImage
	// contains filtered or unexported fields
}

Atlas is itself a draw.Image and contains a number of sub-images.

func New

func New(size int) *Atlas

New creates a new square image atlas of the given size. The bounds will have (0,0) as the minimum and the image is of type NRGBA.

func NewFromImage

func NewFromImage(atlas draw.Image) *Atlas

NewFromImage uses the given image as the destination for all calls to Add. It is assumed to be empty at the beginning so all the available space will be used for sub-images.

func (*Atlas) Add

func (a *Atlas) Add(id string, img image.Image) (SubImage, error)

Add finds a position for the given image in the atlas and copies the image there. It returns the new sub-image. If there is no more space in the atlas, it returns an error.

func (*Atlas) GetSubImageByID

func (a *Atlas) GetSubImageByID(id string) (SubImage, error)

GetSubImageByID returns the first SubImage with the given ID. If none is found, an error is returned.

type SubImage

type SubImage struct {
	draw.Image
	ID string
}

SubImage is a draw.Image with a string ID. The image is always a reference back to the Atlas image, just the bounds are different.

Jump to

Keyboard shortcuts

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