aseprite

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2022 License: MIT Imports: 6 Imported by: 0

README

Aseprite-GO

Go Report Card

Supercharge your Aseprite Workflow with custom scripts and a Go module - Now works with embedded assets, too.

Adam shared some bits and pieces that he uses all the time in Aseprite to speed up his workflow on YouTube.

He and others provided custom scripts which could be used to split a single spritesheet into multiple files by using the tags.

With this Go module you can automatically extract the generated spritesheets and use it in your Go project.

Install the scripts

Copy the .lua files from the plugins folder to your Aspeprite scripts folder and use the Rescan (F5) function.

Scripts

Open example project

Open the sprites folder with Aseprite and open the player.aseprite file.

This spritesheet contains an idle and walk animation facing the up, down, left and right direction. player

Now use the script menu in Aseprite to execute export_tags_to_sheets which creates a corresponding .json and .png file for each tag.

Read the spritesheets with Go


func main() {
    path := filepath.Join("sprites")
    sprites, _ := aseprite.LoadSpritesheet(path)

    frames := sprites["player-idle-down"] // get access to the frames of the animation
    
    duration := frames[0].DurationMs // get the duration in milliseconds
    pos_x := frames[0].PosX // get x and y position in the spritesheet
    pos_y := frames[0].PosY
    png := filepath.Join("sprites", "player-idle-down.png") // spritesheet is always key + .png
}

Now everytime you change something in Aseprite the spritesheets could be immediatly used after using the export scripts!

Support for embedded assets

Since Go 1.16 we have the embed package which enables us to include our assets into the binary. You could read the Spritesheets from there by using the LoadSpritesheetEmbed function.


//go:embed sprites
var sprites embed.FS

func main() {
    path := filepath.Join("sprites")
    sprites, _ := aseprite.LoadSpritesheetEmbed(path, sprites)
    ...
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodePath

func DecodePath(path string) (data map[string]interface{}, err error)

DecodePath ...

func FrameCount

func FrameCount(data map[string]interface{}) (count int)

FrameCount ...

func ImageName

func ImageName(data map[string]interface{}) string

ImageName ...

Types

type Frame

type Frame struct {
	DurationMs float64 `json:"duration_ms"`
	PosX       float32 `json:"pos_x"`
	PosY       float32 `json:"pos_y"`
	SizeX      float32 `json:"size_x"`
	SizeY      float32 `json:"size_y"`
}

Frame stores the data.

func FrameAt

func FrameAt(index int, data map[string]interface{}) (f *Frame)

FrameAt ...

func Frames

func Frames(data map[string]interface{}) (frames []*Frame)

Frames ...

type Spritesheet

type Spritesheet map[string][]*Frame

Spritesheet is a map of frame slices.

func LoadSpritesheet

func LoadSpritesheet(path string) (spritesheet Spritesheet, err error)

LoadSpritesheet ...

func LoadSpritesheetEmbed added in v0.0.2

func LoadSpritesheetEmbed(path string, fs embed.FS) (spritesheet Spritesheet, err error)

LoadSpritesheetEmbed ...

Jump to

Keyboard shortcuts

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