tiles!
This commit is contained in:
parent
aa6cbbf295
commit
a2fb805f41
1 changed files with 16 additions and 2 deletions
|
@ -1,16 +1,30 @@
|
|||
package engine
|
||||
|
||||
import "github.com/hajimehoshi/ebiten/v2"
|
||||
import (
|
||||
"image"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
)
|
||||
|
||||
type Tilemap struct {
|
||||
Map [][]int
|
||||
Src *ebiten.Image
|
||||
TileSize int
|
||||
GeoM *ebiten.GeoM
|
||||
GeoM ebiten.GeoM
|
||||
|
||||
ZPos
|
||||
}
|
||||
|
||||
func (t *Tilemap) Draw(screen *ebiten.Image) {
|
||||
for j, row := range t.Map {
|
||||
for i, tile := range row {
|
||||
var op ebiten.DrawImageOptions
|
||||
op.GeoM.Translate(float64(i*t.TileSize), float64(j*t.TileSize))
|
||||
op.GeoM.Concat(t.GeoM)
|
||||
|
||||
sx := tile * t.TileSize
|
||||
src := t.Src.SubImage(image.Rect(sx, 0, sx+t.TileSize, t.TileSize)).(*ebiten.Image)
|
||||
screen.DrawImage(src, &op)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue