spritesheet

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2020 License: MIT Imports: 10 Imported by: 0

README

This is a commandline tool that I created in order to build spritesheets for the Jumble application.

The tool generates two files:

  • a PNG spritesheet with all images bin packed
  • a JSON file with all sprites metadata (ID and coordinates in the sprite sheet)

Here a generated PNG spritesheet sample:

and the related 👉 generated JSON info

How to use

To generate the spritesheet and the related JSON file with all the sprites locations:

spritesheet ~/Pictures/AWS-Architecture-Icons/PNG/

Alternatively you can specify text file with a list of your images

  • use absolute paths
  • one path for line

and execute the tool like this (note the @ suffix):

spritesheet -o /path/to/destination/  @path/to/your/list.txt

Ho to build

To build this tool, you need GoReleaser.

Grab the source code

git clone https://github.com/lucasepe/spritesheet.git

Change dir to the tool folder

cd spritesheet/cmd

Run GoReleaser

goreleaser --rm-dist --snapshot --skip-publish

you will found the binaries for:

  • MacOS into the folder dist/spritesheet_darwin_amd64
  • Linux into the folder dist/spritesheet_linux_amd64
  • Windows into the folder dist/spritesheet_windows_amd64

Releases ready to use

Here you can find the tool already compiled for:

  • MacOS
  • Linux
  • Windows

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ByWidthAndHeight

type ByWidthAndHeight []*Sprite

ByWidthAndHeight implements sort.Interface based on the Width and Height field.

func (ByWidthAndHeight) Len

func (a ByWidthAndHeight) Len() int

func (ByWidthAndHeight) Less

func (a ByWidthAndHeight) Less(i, j int) bool

func (ByWidthAndHeight) Swap

func (a ByWidthAndHeight) Swap(i, j int)

type Sprite

type Sprite struct {
	ID string `json:"key"`
	X  int    `json:"x"`
	Y  int    `json:"y"`
	W  int    `json:"w"`
	H  int    `json:"h"`
	// contains filtered or unexported fields
}

Sprite describes a frame in the spritesheet.

type Spritesheet

type Spritesheet struct {
	Sprites []*Sprite `json:"frames"`
	Width   int       `json:"width"`
	Height  int       `json:"height"`
}

Spritesheet describes a tileset.

func FromImageList

func FromImageList(images []string) (Spritesheet, error)

FromImageList builds a Spritesheet filled will the specified images slice.

func (*Spritesheet) Image

func (ss *Spritesheet) Image() (image.Image, error)

Image assembles the spritesheet image.

func (*Spritesheet) JSON

func (ss *Spritesheet) JSON() (string, error)

JSON encodes the spritesheet metadata.

func (*Spritesheet) Len

func (ss *Spritesheet) Len() int

Len returns the number of blocks in total.

func (*Spritesheet) Place

func (ss *Spritesheet) Place(n, x, y int)

Place places the block n, at the position [x, y].

func (*Spritesheet) Size

func (ss *Spritesheet) Size(n int) (width, height int)

Size returns the width and height of the block n.

Directories

Path Synopsis
Package binpack implements Jake Gordon's 2D binpacking algorithm.
Package binpack implements Jake Gordon's 2D binpacking algorithm.
cmd

Jump to

Keyboard shortcuts

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