sudoku: optimize text creation of sudoku numbers

This commit optimizes the text creation of sudoku numbers re-using the
`text.Text` used for printing the numbers to the batch.

Fixes #7.
This commit is contained in:
Jason Wangsadinata 2019-02-03 19:47:05 +07:00
parent 6dea3ebe47
commit 91dc0b2643
1 changed files with 4 additions and 1 deletions

View File

@ -95,6 +95,9 @@ func run() {
// initialize batch
batch := pixel.NewBatch(&pixel.TrianglesData{}, atlas.Picture())
// initialize text placeholder
num := text.New(pixel.ZV, atlas)
// setup game
for i := 0; i < 9; i++ {
for j := 0; j < 9; j++ {
@ -185,7 +188,7 @@ func run() {
for a, sa := range board {
for b, sb := range sa {
if sb != 0 {
num := text.New(pixel.ZV, atlas)
num.Clear()
num.WriteString(strconv.Itoa(sb))
num.DrawColorMask(batch,
pixel.IM.