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