starting animations on the right foot?

This commit is contained in:
Josh Deprez 2021-08-05 15:24:16 +10:00 committed by Josh Deprez
parent 46ae8056bc
commit cb157a9503
3 changed files with 10 additions and 3 deletions

View file

@ -10,6 +10,8 @@ type Anim struct {
func (a *Anim) CurrentFrame() int { return a.Def.Frames[a.Index].Frame }
func (a *Anim) Reset() { a.Index, a.Ticks = 0, 0 }
// Update increments the tick count and advances the frame if necessary.
func (a *Anim) Update() error {
a.Ticks++

View file

@ -40,6 +40,11 @@ func (s *Sprite) Draw(screen *ebiten.Image, geom ebiten.GeoM) {
func (s *Sprite) Scan() []interface{} { return []interface{}{&s.Actor} }
func (s *Sprite) SetAnim(a *Anim) { s.anim = a }
func (s *Sprite) SetAnim(a *Anim) {
if s.anim != a {
a.Reset()
}
s.anim = a
}
func (s *Sprite) Update() error { return s.anim.Update() }

View file

@ -65,10 +65,10 @@ func (aw *Awakeman) Update() error {
}
func (aw *Awakeman) Prepare(*engine.Game) {
aw.animRunLeft = &engine.Anim{Def: engine.AnimDefs["aw_run_left"]}
aw.animRunRight = &engine.Anim{Def: engine.AnimDefs["aw_run_right"]}
aw.animIdleLeft = &engine.Anim{Def: engine.AnimDefs["aw_idle_left"]}
aw.animIdleRight = &engine.Anim{Def: engine.AnimDefs["aw_idle_right"]}
aw.animRunLeft = &engine.Anim{Def: engine.AnimDefs["aw_run_left"]}
aw.animRunRight = &engine.Anim{Def: engine.AnimDefs["aw_run_right"]}
}
func (aw *Awakeman) Scan() []interface{} { return []interface{}{&aw.Sprite} }