tile tweaks

This commit is contained in:
Josh Deprez 2021-08-02 15:56:25 +10:00 committed by Josh Deprez
parent 27cbaf9403
commit 8ddfe28427
2 changed files with 10 additions and 4 deletions

View file

@ -33,6 +33,9 @@ func (t *Tilemap) Draw(screen *ebiten.Image, geom ebiten.GeoM) {
geom.Concat(*t.Transform.GeoM())
for j, row := range t.Map {
for i, tile := range row {
if tile == nil {
continue
}
var op ebiten.DrawImageOptions
op.GeoM.Translate(float64(i*t.TileSize), float64(j*t.TileSize))
op.GeoM.Concat(geom)
@ -49,10 +52,10 @@ func (t *Tilemap) Update() error {
if t.Disabled {
return nil
}
for j := range t.Map {
for i := range t.Map[j] {
if tile, ok := t.Map[j][i].(Updater); ok {
if err := tile.Update(); err != nil {
for _, row := range t.Map {
for _, tile := range row {
if u, ok := tile.(Updater); ok {
if err := u.Update(); err != nil {
return err
}
}

View file

@ -69,6 +69,9 @@ func main() {
tiles[6][7] = &engine.AnimatedTile{
AnimRef: engine.AnimRef{Key: "red_tiles"},
}
tiles[2][8] = &engine.AnimatedTile{
AnimRef: engine.AnimRef{Key: "green_tiles"},
}
game := &engine.Game{
ScreenHeight: screenHeight,