diff --git a/ebitenutil/debugprint.go b/ebitenutil/debugprint.go index 2a4addc1b..3428c51e4 100644 --- a/ebitenutil/debugprint.go +++ b/ebitenutil/debugprint.go @@ -54,15 +54,18 @@ func (d *debugPrintState) drawText(rt *ebiten.Image, str string, ox, oy int, c c op.ColorM.Scale(r, g, b, a) x := 0 y := 0 + w, _ := d.textImage.Size() for _, c := range str { - const cw = assets.TextImageCharWidth - const ch = assets.TextImageCharHeight + const ( + cw = assets.CharWidth + ch = assets.CharHeight + ) if c == '\n' { x = 0 y += ch continue } - const n = assets.TextImageWidth / cw + n := w / cw sx := (int(c) % n) * cw sy := (int(c) / n) * ch r := image.Rect(sx, sy, sx+cw, sy+ch) @@ -78,7 +81,7 @@ func (d *debugPrintState) drawText(rt *ebiten.Image, str string, ox, oy int, c c // DebugPrint prints the given text str on the given image r. func (d *debugPrintState) DebugPrint(r *ebiten.Image, str string) { if d.textImage == nil { - img := assets.TextImage() + img := assets.CreateTextImage() d.textImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterNearest) } if d.debugPrintRenderTarget == nil { diff --git a/ebitenutil/internal/assets/assets.go b/ebitenutil/internal/assets/assets.go index de8f06764..6a1fae034 100644 --- a/ebitenutil/internal/assets/assets.go +++ b/ebitenutil/internal/assets/assets.go @@ -25,13 +25,11 @@ import ( ) const ( - TextImageWidth = 192 - TextImageHeight = 128 - TextImageCharWidth = TextImageWidth / 32 - TextImageCharHeight = TextImageHeight / 8 + CharWidth = 6 + CharHeight = 16 ) -func TextImage() image.Image { +func CreateTextImage() image.Image { img, _, err := image.Decode(bytes.NewBuffer(textPng)) if err != nil { panic(fmt.Sprintf("assets: image.Decode failed, %v", err))