aseplayer

package module
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2026 License: MIT Imports: 7 Imported by: 0

README

GoDoc

aseplayer

Aseprite animation player for Ebitengine.

There are two methods available to read Aseprite files.

animPlayer := aseplayer.NewAnimPlayerFromAsepriteFile("player.ase")
animPlayer := aseplayer.NewAnimPlayerFromAsepriteFileSystem(fsys, "player.ase")

[!NOTE]
Layers are flattened, blending modes are applied, and frames are arranged on a single texture atlas. Invisible and reference layers are ignored.

Tags

Each Aseprite Tag is imported as an Animation{} struct and is ready to play. Each Tag's frames are stored as a []*ebiten.Image.

Tags

Tag properties

Animation Directions

AsePlayer supports three Animation Directions: Forward, Reverse, and Ping-pong.

dir

[!NOTE]
For Ping-Pong and Reverse playback, the Frames []*ebiten.Image slice is specifically manipulated. For Ping-Pong, the number of frames will be greater than the Aseprite range. [0 1 2 3] -> [0 1 2 3 2 1]. Reverse is an reversed []*ebiten.Image.

Repeat

AsePlayer supports the Repeat property; Animation.Repeat = 0 means infinite loop.

repeat
// Override.
g.animPlayer.Animations["turn"].Repeat = 1

Frame Durations

Frame durations are supported. The animation plays according to these durations.

// Override the third "walk" frame's duration.
animPlayer.Animations["walk"].Durations[2] = time.Millisecond * 100

Usage

A pseudo-code for basic usage with Play()

func (g *Game) Update() error {
	if inpututil.IsKeyJustPressed(ebiten.KeyRight) {
		g.AnimPlayer.Play("walk")
	}
	if inpututil.IsKeyJustPressed(ebiten.KeySpace) {
		g.AnimPlayer.Play("jump")
	}
	// Update AnimPlayer
	g.myAnimPlayer.Update(aseplayer.Delta)
	return nil
}

func (g *Game) Draw(s *ebiten.Image) {
	// Draw AnimPlayer
	s.DrawImage(g.myAnimPlayer.CurrentFrame, nil)
}

Documentation

Index

Constants

View Source
const Delta = time.Second / 60

Variables

This section is empty.

Functions

This section is empty.

Types

type AnimPlayer

type AnimPlayer struct {

	// The frame of the animation currently being played
	CurrentFrame *ebiten.Image

	// The animation currently being played
	CurrentAnimation *Animation

	// Animations accessible by their Aseprite tag names
	Animations map[string]*Animation

	// Sprite atlas containing all animations
	Atlas *ebiten.Image

	// If true, the animation is paused
	Paused bool
	// contains filtered or unexported fields
}

AnimPlayer plays and manages Aseprite tag animations.

func NewAnimPlayerFromAsepriteFile

func NewAnimPlayerFromAsepriteFile(asePath string) *AnimPlayer

The first Aseprite tag will be assigned as CurrentAnimation.

Do not read .ase/.aseprite files that do not have a tag.

func NewAnimPlayerFromAsepriteFileSystem

func NewAnimPlayerFromAsepriteFileSystem(fs fs.FS, asePath string) *AnimPlayer

The first Aseprite tag will be assigned as CurrentAnimation.

Do not read .ase/.aseprite files that do not have a tag.

func (*AnimPlayer) IsEnded added in v1.4.0

func (a *AnimPlayer) IsEnded() bool

If Animation.Repeat is not zero, it returns true when the animation ends. If it is zero, it is always false.

func (*AnimPlayer) Play added in v1.4.0

func (a *AnimPlayer) Play(tag string)

Play rewinds and plays the animation.

func (*AnimPlayer) PlayIfNotCurrent added in v1.4.0

func (a *AnimPlayer) PlayIfNotCurrent(tag string)

PlayIfNotCurrent rewinds and plays the animation with the given tag if it's not already playing

func (*AnimPlayer) Rewind added in v1.4.0

func (a *AnimPlayer) Rewind()

Rewinds animation

func (*AnimPlayer) String added in v1.4.0

func (a *AnimPlayer) String() string

func (*AnimPlayer) Update

func (a *AnimPlayer) Update(dt time.Duration)

type Animation

type Animation struct {

	// The animation tag name is identical to the Aseprite file
	Tag string

	// Animation frames
	Frames []*ebiten.Image

	// Frame durations retrieved from the Aseprite file
	Durations []time.Duration

	// Repeat specifies how many times the animation should loop.
	// A value of 0 means infinite looping.
	Repeat uint16
}

Animation for AnimPlayer

Directories

Path Synopsis
examples
ase_test command

Jump to

Keyboard shortcuts

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