Skip to content

setanarut/aseplayer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)
}