added speed to animation
This commit is contained in:
parent
c9feadf547
commit
64d8907741
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user