Do geom on stack?
This commit is contained in:
parent
76bcda2df5
commit
b976b849b7
3 changed files with 6 additions and 7 deletions
|
@ -11,7 +11,7 @@ import (
|
||||||
// PerfDisplay debugprints CurrentTPS and CurrentFPS in the top left.
|
// PerfDisplay debugprints CurrentTPS and CurrentFPS in the top left.
|
||||||
type PerfDisplay struct{}
|
type PerfDisplay struct{}
|
||||||
|
|
||||||
func (PerfDisplay) Draw(screen *ebiten.Image) {
|
func (PerfDisplay) Draw(screen *ebiten.Image, _ ebiten.GeoM) {
|
||||||
ebitenutil.DebugPrint(screen, fmt.Sprintf("TPS: %0.2f FPS: %0.2f", ebiten.CurrentTPS(), ebiten.CurrentFPS()))
|
ebitenutil.DebugPrint(screen, fmt.Sprintf("TPS: %0.2f FPS: %0.2f", ebiten.CurrentTPS(), ebiten.CurrentFPS()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,9 +12,9 @@ type Updater interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Drawer is a component that can draw itself. Draw is called often.
|
// Drawer is a component that can draw itself. Draw is called often.
|
||||||
// DrawAfter is used to reorder components.
|
// Z is used to reorder components.
|
||||||
type Drawer interface {
|
type Drawer interface {
|
||||||
Draw(*ebiten.Image)
|
Draw(screen *ebiten.Image, geom ebiten.GeoM)
|
||||||
Z() float64
|
Z() float64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ func (g *Game) Update() error {
|
||||||
func (g *Game) Draw(screen *ebiten.Image) {
|
func (g *Game) Draw(screen *ebiten.Image) {
|
||||||
for _, c := range g.Components {
|
for _, c := range g.Components {
|
||||||
if d, ok := c.(Drawer); ok {
|
if d, ok := c.(Drawer); ok {
|
||||||
d.Draw(screen)
|
d.Draw(screen, ebiten.GeoM{})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,17 +10,16 @@ type Tilemap struct {
|
||||||
Map [][]Tile
|
Map [][]Tile
|
||||||
Src *ebiten.Image // must be a horizontal tile set
|
Src *ebiten.Image // must be a horizontal tile set
|
||||||
TileSize int
|
TileSize int
|
||||||
GeoM ebiten.GeoM
|
|
||||||
|
|
||||||
ZPos
|
ZPos
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Tilemap) Draw(screen *ebiten.Image) {
|
func (t *Tilemap) Draw(screen *ebiten.Image, geom ebiten.GeoM) {
|
||||||
for j, row := range t.Map {
|
for j, row := range t.Map {
|
||||||
for i, tile := range row {
|
for i, tile := range row {
|
||||||
var op ebiten.DrawImageOptions
|
var op ebiten.DrawImageOptions
|
||||||
op.GeoM.Translate(float64(i*t.TileSize), float64(j*t.TileSize))
|
op.GeoM.Translate(float64(i*t.TileSize), float64(j*t.TileSize))
|
||||||
op.GeoM.Concat(t.GeoM)
|
op.GeoM.Concat(geom)
|
||||||
|
|
||||||
sx := tile.TileIndex() * t.TileSize
|
sx := tile.TileIndex() * t.TileSize
|
||||||
src := t.Src.SubImage(image.Rect(sx, 0, sx+t.TileSize, t.TileSize)).(*ebiten.Image)
|
src := t.Src.SubImage(image.Rect(sx, 0, sx+t.TileSize, t.TileSize)).(*ebiten.Image)
|
||||||
|
|
Loading…
Reference in a new issue