starting animations on the right foot?
This commit is contained in:
parent
46ae8056bc
commit
cb157a9503
3 changed files with 10 additions and 3 deletions
|
@ -10,6 +10,8 @@ type Anim struct {
|
||||||
|
|
||||||
func (a *Anim) CurrentFrame() int { return a.Def.Frames[a.Index].Frame }
|
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.
|
// Update increments the tick count and advances the frame if necessary.
|
||||||
func (a *Anim) Update() error {
|
func (a *Anim) Update() error {
|
||||||
a.Ticks++
|
a.Ticks++
|
||||||
|
|
|
@ -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) 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() }
|
func (s *Sprite) Update() error { return s.anim.Update() }
|
||||||
|
|
|
@ -65,10 +65,10 @@ func (aw *Awakeman) Update() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (aw *Awakeman) Prepare(*engine.Game) {
|
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.animIdleLeft = &engine.Anim{Def: engine.AnimDefs["aw_idle_left"]}
|
||||||
aw.animIdleRight = &engine.Anim{Def: engine.AnimDefs["aw_idle_right"]}
|
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} }
|
func (aw *Awakeman) Scan() []interface{} { return []interface{}{&aw.Sprite} }
|
||||||
|
|
Loading…
Reference in a new issue