From 64d89077414fb63f007337688efd4ce82ac48b35 Mon Sep 17 00:00:00 2001 From: Jalen Winslow Date: Wed, 24 Jan 2018 06:04:24 -0700 Subject: [PATCH] added speed to animation --- gameobjects/animate.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gameobjects/animate.go b/gameobjects/animate.go index 79aef2a..66c866b 100644 --- a/gameobjects/animate.go +++ b/gameobjects/animate.go @@ -17,6 +17,7 @@ type Animate struct { Frame int Current []pixel.Rect SprSheet pixel.Picture + Speed int64 } func NewAnimation(spriteSheet pixel.Picture, sprFrames []pixel.Rect) Animate { @@ -39,6 +40,7 @@ func NewAnimation(spriteSheet pixel.Picture, sprFrames []pixel.Rect) Animate { animation.Sprite = pixel.NewSprite(spriteSheet, animation.Current[0]) animation.Frame = 0 animation.Idle = false + animation.Speed = 6 return animation } @@ -57,9 +59,9 @@ func (a *Animate) Update(dt int64) { a.Current = a.Right } elapsedTime += dt - if elapsedTime >= 1000000000/10 { + if elapsedTime >= 1000000000/ a.Speed{ a.Frame++ - elapsedTime -= 1000000000 / 10 + elapsedTime -= 1000000000 / a.Speed } if a.Frame >= 3 { a.Frame = 0