ebitentextureunpacker

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: May 29, 2023 License: GPL-3.0 Imports: 5 Imported by: 0

README

Go Reference

EbitenTextureUnpacker

Purpose of this library is to unpack sprite sheets packed using Texture Packer.

This implementation is for Texture Packer's JSON Array format.

Usage

First generate the packed PNG file and place the json and PNG file wherever you keep your assets.

Add this package to your project.

go get github.com/jodios/ebitentextureunpacker/v2

Create an embed file to embed all of your assets into the actual executable of your game.

package assets
import (
	_ "embed"
)
var (
	//go:embed sample_spritesheet.json
	Spritesheet_JSON []byte
	//go:embed sample_spritesheet.png
	Spritesheet_PNG []byte
)

Create an Unpacker with the path to your assets folder and call the Unpack function.

func init() {
	unpacker := &Unpacker{}
	var err error
	sprites, err = unpacker.Unpack(assets.Spritesheet_JSON, assets.Spritesheet_PNG)
	if err != nil {
		log.Fatal(err)
	}
}

Unpack returns a map of image names to images so you can access the sprite you need by the original file name.
Example...

downIdle := sprites["orange_down_idle.png"]

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ImageWithFrameDetails added in v1.1.0

type ImageWithFrameDetails struct {
	Image     *ebiten.Image
	FrameData TexturePackerFrame
}

type TexturePackerFrame added in v1.1.0

type TexturePackerFrame struct {
	Filename string `json:"filename,omitempty"`
	Rotated  bool   `json:"rotated,omitempty"`
	Trimmed  bool   `json:"trimmed,omitempty"`
	Frame    struct {
		X int `json:"x,omitempty"`
		Y int `json:"y,omitempty"`
		W int `json:"w,omitempty"`
		H int `json:"h,omitempty"`
	} `json:"frame"`
	SpriteSourceSize struct {
		X int `json:"x,omitempty"`
		Y int `json:"y,omitempty"`
		W int `json:"w,omitempty"`
		H int `json:"h,omitempty"`
	} `json:"spriteSourceSize"`
	SourceSize struct {
		W int `json:"w,omitempty"`
		H int `json:"h,omitempty"`
	} `json:"sourceSize,omitempty"`
}

type TexturePackerJSONArray

type TexturePackerJSONArray struct {
	Frames []TexturePackerFrame `json:"frames,omitempty"`
	Meta   struct {
		App     string `json:"app,omitempty"`
		Version string `json:"version,omitempty"`
		Image   string `json:"image,omitempty"`
		Format  string `json:"format,omitempty"`
		Size    struct {
			W int `json:"w,omitempty"`
			H int `json:"h,omitempty"`
		} `json:"size,omitempty"`
		Scale       string `json:"scale,omitempty"`
		Smartupdate string `json:"smartupdate,omitempty"`
	}
}

type Unpacker

type Unpacker struct{}

func (*Unpacker) Unpack

func (unpacker *Unpacker) Unpack(arrayFile []byte, packedImage []byte) (map[string]*ebiten.Image, error)

func (*Unpacker) UnpackWithFrameDetails added in v1.1.0

func (unpacker *Unpacker) UnpackWithFrameDetails(arrayFile []byte, packedImage []byte) (map[string]ImageWithFrameDetails, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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