added duration from asesprite json, background animation, prepared
idle animation
This commit is contained in:
@@ -36,7 +36,7 @@ func (system *AnimationSystem) Update() error {
|
||||
if render.Animate.Timer.IsReady() {
|
||||
switch {
|
||||
// animation shows from earlier tick, animate
|
||||
case render.Animate.Index > -1 && render.Animate.Index < len(render.Animate.Tiles)-1:
|
||||
case render.Animate.Index > -1 && render.Animate.Index < len(render.Animate.Sprites)-1:
|
||||
render.Animate.Index += 1
|
||||
render.Animate.Timer.Start(config.ANIMATION_LOOPWAIT)
|
||||
default:
|
||||
@@ -71,7 +71,7 @@ func (system *AnimationSystem) Draw(screen *ebiten.Image) {
|
||||
if render.Animate.Active {
|
||||
op.GeoM.Reset()
|
||||
op.GeoM.Translate(float64(pos.X), float64(pos.Y))
|
||||
screen.DrawImage(render.Animate.Tiles[render.Animate.Index], op)
|
||||
screen.DrawImage(render.Animate.GetSprite(), op)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package systems
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"openquell/assets"
|
||||
"openquell/components"
|
||||
. "openquell/components"
|
||||
@@ -51,9 +50,9 @@ func NewGridSystem(world *ecs.World, width, height,
|
||||
system.BackgroundAnimated = true
|
||||
|
||||
system.Animate = components.Animation{
|
||||
Active: true,
|
||||
Loop: true,
|
||||
Tiles: assets.Animations[background+"-animated"].Sprites,
|
||||
Active: true,
|
||||
Loop: true,
|
||||
Sprites: assets.Animations[background+"-animated"].Sprites,
|
||||
}
|
||||
|
||||
system.Animate.Timer.Start(config.ANIMATION_LOOPWAIT)
|
||||
@@ -64,13 +63,12 @@ func NewGridSystem(world *ecs.World, width, height,
|
||||
|
||||
func (system *GridSystem) Update() error {
|
||||
if system.BackgroundAnimated {
|
||||
slog.Debug("animate bg?", "timer", system.Animate.Timer)
|
||||
if system.Animate.Timer.IsReady() {
|
||||
switch {
|
||||
// animation shows from earlier tick, animate
|
||||
case system.Animate.Index > -1 && system.Animate.Index < len(system.Animate.Tiles)-1:
|
||||
case system.Animate.Index > -1 && system.Animate.Index < len(system.Animate.Sprites)-1:
|
||||
system.Animate.Index += 1
|
||||
system.Animate.Timer.Start(config.ANIMATION_LOOPWAIT)
|
||||
system.Animate.Timer.Start(system.Animate.GetDuration())
|
||||
default:
|
||||
// last sprite reached
|
||||
if system.Animate.Loop {
|
||||
@@ -93,7 +91,7 @@ func (system *GridSystem) Draw(screen *ebiten.Image) {
|
||||
if !system.UseCache || query.Count() != system.Count || system.BackgroundAnimated {
|
||||
// map not cached or cacheable, write it to the cache
|
||||
if system.BackgroundAnimated {
|
||||
system.Cache.DrawImage(system.Animate.Tiles[system.Animate.Index], op)
|
||||
system.Cache.DrawImage(system.Animate.GetSprite(), op)
|
||||
} else {
|
||||
system.Cache.DrawImage(system.Background, op)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user