started animation background
This commit is contained in:
parent
50dd76a268
commit
0b0252022e
@ -32,7 +32,7 @@ type AnimationGeo struct {
|
|||||||
|
|
||||||
type AnimationFrame struct {
|
type AnimationFrame struct {
|
||||||
Position AnimationGeo `json:"frame"`
|
Position AnimationGeo `json:"frame"`
|
||||||
// FIXME: maybe also add delay etc? might be cool to tweak these things from LDTK
|
Duration int
|
||||||
}
|
}
|
||||||
|
|
||||||
type AnimationMeta struct {
|
type AnimationMeta struct {
|
||||||
|
|||||||
72
assets/sprites/backgroundstars-animated.json
Normal file
72
assets/sprites/backgroundstars-animated.json
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
{ "frames": [
|
||||||
|
{
|
||||||
|
"filename": "backgroundstars 0.ase",
|
||||||
|
"frame": { "x": 0, "y": 0, "w": 640, "h": 384 },
|
||||||
|
"rotated": false,
|
||||||
|
"trimmed": false,
|
||||||
|
"spriteSourceSize": { "x": 0, "y": 0, "w": 640, "h": 384 },
|
||||||
|
"sourceSize": { "w": 640, "h": 384 },
|
||||||
|
"duration": 500
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"filename": "backgroundstars 1.ase",
|
||||||
|
"frame": { "x": 640, "y": 0, "w": 640, "h": 384 },
|
||||||
|
"rotated": false,
|
||||||
|
"trimmed": false,
|
||||||
|
"spriteSourceSize": { "x": 0, "y": 0, "w": 640, "h": 384 },
|
||||||
|
"sourceSize": { "w": 640, "h": 384 },
|
||||||
|
"duration": 100
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"filename": "backgroundstars 2.ase",
|
||||||
|
"frame": { "x": 1280, "y": 0, "w": 640, "h": 384 },
|
||||||
|
"rotated": false,
|
||||||
|
"trimmed": false,
|
||||||
|
"spriteSourceSize": { "x": 0, "y": 0, "w": 640, "h": 384 },
|
||||||
|
"sourceSize": { "w": 640, "h": 384 },
|
||||||
|
"duration": 500
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"filename": "backgroundstars 3.ase",
|
||||||
|
"frame": { "x": 1920, "y": 0, "w": 640, "h": 384 },
|
||||||
|
"rotated": false,
|
||||||
|
"trimmed": false,
|
||||||
|
"spriteSourceSize": { "x": 0, "y": 0, "w": 640, "h": 384 },
|
||||||
|
"sourceSize": { "w": 640, "h": 384 },
|
||||||
|
"duration": 100
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"filename": "backgroundstars 4.ase",
|
||||||
|
"frame": { "x": 2560, "y": 0, "w": 640, "h": 384 },
|
||||||
|
"rotated": false,
|
||||||
|
"trimmed": false,
|
||||||
|
"spriteSourceSize": { "x": 0, "y": 0, "w": 640, "h": 384 },
|
||||||
|
"sourceSize": { "w": 640, "h": 384 },
|
||||||
|
"duration": 500
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"filename": "backgroundstars 5.ase",
|
||||||
|
"frame": { "x": 3200, "y": 0, "w": 640, "h": 384 },
|
||||||
|
"rotated": false,
|
||||||
|
"trimmed": false,
|
||||||
|
"spriteSourceSize": { "x": 0, "y": 0, "w": 640, "h": 384 },
|
||||||
|
"sourceSize": { "w": 640, "h": 384 },
|
||||||
|
"duration": 100
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"meta": {
|
||||||
|
"app": "http://www.aseprite.org/",
|
||||||
|
"version": "1.x-dev",
|
||||||
|
"image": "backgroundstars-animated.png",
|
||||||
|
"format": "RGBA8888",
|
||||||
|
"size": { "w": 3840, "h": 384 },
|
||||||
|
"scale": "1",
|
||||||
|
"frameTags": [
|
||||||
|
],
|
||||||
|
"layers": [
|
||||||
|
{ "name": "Layer", "opacity": 255, "blendMode": "normal" }
|
||||||
|
],
|
||||||
|
"slices": [
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
assets/sprites/backgroundstars-animated.png
Normal file
BIN
assets/sprites/backgroundstars-animated.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 21 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 13 KiB |
@ -37,10 +37,11 @@ func NewLevel(game *Game, cellsize int, plan *ldtkgo.Level) *Level {
|
|||||||
systemlist := []systems.System{}
|
systemlist := []systems.System{}
|
||||||
|
|
||||||
gridcontainer := &grid.GridContainer{}
|
gridcontainer := &grid.GridContainer{}
|
||||||
|
bgimage := util.GetBGImage(plan)
|
||||||
|
|
||||||
systemlist = append(systemlist,
|
systemlist = append(systemlist,
|
||||||
systems.NewGridSystem(game.World, game.ScreenWidth, game.ScreenHeight, cellsize,
|
systems.NewGridSystem(game.World, game.ScreenWidth, game.ScreenHeight, cellsize,
|
||||||
assets.Assets[util.GetBGImage(plan)]))
|
bgimage))
|
||||||
|
|
||||||
systemlist = append(systemlist, systems.NewCollectibleSystem(game.World, cellsize))
|
systemlist = append(systemlist, systems.NewCollectibleSystem(game.World, cellsize))
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,14 @@
|
|||||||
package systems
|
package systems
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log/slog"
|
||||||
|
"openquell/assets"
|
||||||
|
"openquell/components"
|
||||||
. "openquell/components"
|
. "openquell/components"
|
||||||
|
"openquell/config"
|
||||||
|
"openquell/util"
|
||||||
|
|
||||||
|
"log"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/v2"
|
"github.com/hajimehoshi/ebiten/v2"
|
||||||
"github.com/mlange-42/arche/ecs"
|
"github.com/mlange-42/arche/ecs"
|
||||||
@ -15,14 +22,20 @@ type GridSystem struct {
|
|||||||
Cache *ebiten.Image
|
Cache *ebiten.Image
|
||||||
Count int // register tile count, invalidates cache
|
Count int // register tile count, invalidates cache
|
||||||
Background *ebiten.Image
|
Background *ebiten.Image
|
||||||
|
Animate components.Animation
|
||||||
|
BackgroundAnimated bool
|
||||||
Width, Height, Tilesize int
|
Width, Height, Tilesize int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGridSystem(world *ecs.World, width, height,
|
func NewGridSystem(world *ecs.World, width, height,
|
||||||
tilesize int, background *ebiten.Image) System {
|
tilesize int, background string) System {
|
||||||
|
|
||||||
cache := ebiten.NewImage(width, height)
|
cache := ebiten.NewImage(width, height)
|
||||||
|
|
||||||
|
if !util.Exists(assets.Assets, background) {
|
||||||
|
log.Fatalf("no background %s in assets", background)
|
||||||
|
}
|
||||||
|
|
||||||
system := &GridSystem{
|
system := &GridSystem{
|
||||||
Selector: generic.NewFilter3[Renderable, Position, Solid](),
|
Selector: generic.NewFilter3[Renderable, Position, Solid](),
|
||||||
UseCache: false,
|
UseCache: false,
|
||||||
@ -30,14 +43,46 @@ func NewGridSystem(world *ecs.World, width, height,
|
|||||||
Width: width,
|
Width: width,
|
||||||
Height: height,
|
Height: height,
|
||||||
Tilesize: tilesize,
|
Tilesize: tilesize,
|
||||||
Background: background,
|
Background: assets.Assets[background],
|
||||||
World: world,
|
World: world,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if util.Exists(assets.Animations, background+"-animated") {
|
||||||
|
system.BackgroundAnimated = true
|
||||||
|
|
||||||
|
system.Animate = components.Animation{
|
||||||
|
Active: true,
|
||||||
|
Loop: true,
|
||||||
|
Tiles: assets.Animations[background+"-animated"].Sprites,
|
||||||
|
}
|
||||||
|
|
||||||
|
system.Animate.Timer.Start(config.ANIMATION_LOOPWAIT)
|
||||||
|
}
|
||||||
|
|
||||||
return system
|
return system
|
||||||
}
|
}
|
||||||
|
|
||||||
func (system *GridSystem) Update() error {
|
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:
|
||||||
|
system.Animate.Index += 1
|
||||||
|
system.Animate.Timer.Start(config.ANIMATION_LOOPWAIT)
|
||||||
|
default:
|
||||||
|
// last sprite reached
|
||||||
|
if system.Animate.Loop {
|
||||||
|
system.Animate.Index = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
system.Animate.Timer.Update()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,9 +90,13 @@ func (system *GridSystem) Draw(screen *ebiten.Image) {
|
|||||||
op := &ebiten.DrawImageOptions{}
|
op := &ebiten.DrawImageOptions{}
|
||||||
query := system.Selector.Query(system.World)
|
query := system.Selector.Query(system.World)
|
||||||
|
|
||||||
if !system.UseCache || query.Count() != system.Count {
|
if !system.UseCache || query.Count() != system.Count || system.BackgroundAnimated {
|
||||||
// map not cached or cacheable, write it to the cache
|
// map not cached or cacheable, write it to the cache
|
||||||
system.Cache.DrawImage(system.Background, op)
|
if system.BackgroundAnimated {
|
||||||
|
system.Cache.DrawImage(system.Animate.Tiles[system.Animate.Index], op)
|
||||||
|
} else {
|
||||||
|
system.Cache.DrawImage(system.Background, op)
|
||||||
|
}
|
||||||
|
|
||||||
system.Count = query.Count()
|
system.Count = query.Count()
|
||||||
counter := 0
|
counter := 0
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user