added duration from asesprite json, background animation, prepared

idle animation
This commit is contained in:
2024-04-07 19:10:27 +02:00
parent 0b0252022e
commit 2edaccbfda
12 changed files with 216 additions and 23 deletions

View File

@@ -1,7 +1,9 @@
package components
import (
"openquell/assets"
"openquell/config"
"time"
"github.com/hajimehoshi/ebiten/v2"
)
@@ -11,7 +13,7 @@ type Animation struct {
Active bool // animation is running
Loop bool // remove the entity if false, loop endless otherwise
Index int // where we are currently
Tiles []*ebiten.Image
Sprites []assets.AnimationSprite
Width, Height int // single sprite measurements
Timer Timer
Trigger string
@@ -24,6 +26,7 @@ type Renderable struct {
Damaged int
Shader *ebiten.Shader
Animate Animation
IdleAnimate Animation
Hidden bool
}
@@ -41,3 +44,11 @@ func (render *Renderable) StartAnimation() {
render.Animate.Loop = true
}
}
func (animation *Animation) GetSprite() *ebiten.Image {
return animation.Sprites[animation.Index].Sprite
}
func (animation *Animation) GetDuration() time.Duration {
return animation.Sprites[animation.Index].Duration * time.Millisecond
}