From 3f52fb951bb2d6cfa6f4e29497fb7cb64618a8d7 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Wed, 16 Aug 2017 00:09:20 +0900 Subject: [PATCH] examples/runes: Refactoring --- examples/runes/main.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/examples/runes/main.go b/examples/runes/main.go index 586e86a96..030353af3 100644 --- a/examples/runes/main.go +++ b/examples/runes/main.go @@ -18,22 +18,21 @@ package main import ( "log" + "strings" "github.com/hajimehoshi/ebiten" "github.com/hajimehoshi/ebiten/ebitenutil" ) var ( - runes = append(make([]rune, 0, 1024), []rune("Type on the keyboard:\n")...) + text = "Type on the keyboard:\n" counter = 0 ) func update(screen *ebiten.Image) error { - runes = append(runes, ebiten.InputChars()...) - if ebiten.IsKeyPressed(ebiten.KeyEnter) { - if len(runes) > 0 && runes[len(runes)-1] != '\n' { - runes = append(runes, '\n') - } + text += string(ebiten.InputChars()) + if ebiten.IsKeyPressed(ebiten.KeyEnter) && !strings.HasSuffix(text, "\n") { + text += "\n" } counter++ @@ -41,10 +40,12 @@ func update(screen *ebiten.Image) error { return nil } + t := text if counter%60 < 30 { - return ebitenutil.DebugPrint(screen, string(append(runes, '_'))) + t += "_" } - return ebitenutil.DebugPrint(screen, string(runes)) + ebitenutil.DebugPrint(screen, t) + return nil } func main() {