From 91dc0b2643e0eb395a2a06c9e8436dfb42288d77 Mon Sep 17 00:00:00 2001 From: Jason Wangsadinata Date: Sun, 3 Feb 2019 19:47:05 +0700 Subject: [PATCH] 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. --- community/sudoku/sudoku.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/community/sudoku/sudoku.go b/community/sudoku/sudoku.go index 882987c..c1b3888 100644 --- a/community/sudoku/sudoku.go +++ b/community/sudoku/sudoku.go @@ -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.