aseprite

package module
v0.0.0-...-81f7063 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2022 License: MIT Imports: 7 Imported by: 1

README

ebiten-aseprite

Parse and render aseprite animations in ebiten

Usage

  • create an animation in aseprite
  • export both the png and the json file
import aseprite "github.com/tducasse/ebiten-aseprite"

//go:embed assets/*
var assetsFolder embed.FS

type Player struct {
	X              float64
	Y              float64
	Sprite         *aseprite.Animation
}

p := &Player{}

p.Sprite = aseprite.Load(
  // name of your aseprite .json file
  "player.json",
  &aseprite.Options{
    // embed your assets folder first
    EmbedFolder: assetsFolder,
    // path to where you store your images
    Root:        "assets/images",
  },
  // which tag to start with
  "idle",
  // we need to pass the whole entity as well
  p,
)

// define a callback function, called every time we reach the end of the current tag
func onAnimLoop(player interface{}, anim *aseprite.Animation) {
  // do something here
}

// attach it to the animation
p.Sprite.OnLoop(onAnimLoop)

// update the animation in your Update call
p.Sprite.Update()
// move to another tag (if it's already playing, it's just ignored)
p.Sprite.SetTag("walk")

// draw the animation in your Draw call
p.Sprite.Draw(p.X, p.Y, screen)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Animation

type Animation struct {
	Tags            map[string]*Tag
	Frames          []*Frame
	CurrentTag      *Tag
	CurrentFrame    *Frame
	CurrentFrameIdx int
	FrameCounter    float64
	Options         *Options
	Image           *ebiten.Image
	OnLoopCallback  OnLoopType
	Instance        interface{}
}

func Load

func Load(path string, opt *Options, tag string, instance interface{}) *Animation

func (*Animation) Draw

func (anim *Animation) Draw(x float64, y float64, screen *ebiten.Image)

func (*Animation) GetFrames

func (anim *Animation) GetFrames(frames map[string]interface{})

func (*Animation) GetImage

func (anim *Animation) GetImage(meta map[string]interface{})

func (*Animation) GetTags

func (anim *Animation) GetTags(meta map[string]interface{})

func (*Animation) Init

func (anim *Animation) Init(aseData map[string]interface{}, tag string)

func (*Animation) OnLoop

func (anim *Animation) OnLoop(callback OnLoopType)

func (*Animation) SetTag

func (anim *Animation) SetTag(tag string)

func (*Animation) Update

func (anim *Animation) Update()

type Frame

type Frame struct {
	Image    *ebiten.Image
	Duration float64
}

type OnLoopType

type OnLoopType func(interface{}, *Animation)

type Options

type Options struct {
	// a pointer to the folder containing assets
	EmbedFolder *embed.FS
	// the root path to the aseprite assets (json and png)
	Root string
}

type Tag

type Tag struct {
	From int
	To   int
	Name string
}

Jump to

Keyboard shortcuts

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