mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 20:18:59 +01:00
ebitenutil: Cache sub images for debug print
This commit is contained in:
parent
21ba42325c
commit
a449045ae2
@ -22,7 +22,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
debugPrintTextImage *ebiten.Image
|
debugPrintTextImage *ebiten.Image
|
||||||
|
debugPrintTextSubImages = map[rune]*ebiten.Image{}
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -66,13 +67,18 @@ func drawDebugText(rt *ebiten.Image, str string, ox, oy int, shadow bool) {
|
|||||||
y += ch
|
y += ch
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
n := w / cw
|
s, ok := debugPrintTextSubImages[c]
|
||||||
sx := (int(c) % n) * cw
|
if !ok {
|
||||||
sy := (int(c) / n) * ch
|
n := w / cw
|
||||||
|
sx := (int(c) % n) * cw
|
||||||
|
sy := (int(c) / n) * ch
|
||||||
|
s = debugPrintTextImage.SubImage(image.Rect(sx, sy, sx+cw, sy+ch)).(*ebiten.Image)
|
||||||
|
debugPrintTextSubImages[c] = s
|
||||||
|
}
|
||||||
op.GeoM.Reset()
|
op.GeoM.Reset()
|
||||||
op.GeoM.Translate(float64(x), float64(y))
|
op.GeoM.Translate(float64(x), float64(y))
|
||||||
op.GeoM.Translate(float64(ox+1), float64(oy))
|
op.GeoM.Translate(float64(ox+1), float64(oy))
|
||||||
_ = rt.DrawImage(debugPrintTextImage.SubImage(image.Rect(sx, sy, sx+cw, sy+ch)).(*ebiten.Image), op)
|
_ = rt.DrawImage(s, op)
|
||||||
x += cw
|
x += cw
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user