Skip to content

setanarut/aseplayer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GoDoc

aseplayer

Aseprite animation player for Ebitengine.

Note

Only the topmost visible layer is considered. Others are ignored..

Parsing Aseprite file

fly, _ = aseplayer.NewAnimPlayerFromAsepriteFile("bird.ase")

Tags

Each Aseprite Tag is imported as an Animation{} struct and is ready to play.

Playing tags

To play multiple animation tags simultaneously, use a shallow copy of AnimPlayer. It will share the same animations. Update each AnimPlayer with Update() and draw it with Draw().

bird1, _ = aseplayer.NewAnimPlayerFromAsepriteFile("bird.ase", aseplayer.Default)
bird2 = *bird1
bird3 = *bird1

bird1.Play("fly")
bird2.Play("fly")
bird3.Play("walk")

Tag properties

Animation Directions

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

Note

For Ping-Pong and Reverse playback, the []Frame 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 []Frame.

Repeat

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

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

UserData

Text field of Aseprite Tag's User Data. It is useful for data transfer. It can be automated with Aseprite Lua scripting. https://www.aseprite.org/api/tag#tagdata

Frame Durations

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

// Override frame's duration.
animPlayer.Animations["walk"].Frames[2].Duration = 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.Image, nil)
}