examples/runes: Refactoring

This commit is contained in:
Hajime Hoshi 2017-08-15 12:14:01 +09:00
parent 5f47622807
commit 78ed445111

View File

@ -23,11 +23,10 @@ import (
"github.com/hajimehoshi/ebiten/ebitenutil" "github.com/hajimehoshi/ebiten/ebitenutil"
) )
var runes = append(make([]rune, 0, 1024), []rune("Type on the keyboard:\n")...) var (
runes = append(make([]rune, 0, 1024), []rune("Type on the keyboard:\n")...)
var buf = make([]rune, 1024) counter = 0
)
var counter int
func update(screen *ebiten.Image) error { func update(screen *ebiten.Image) error {
runes = append(runes, ebiten.InputChars()...) runes = append(runes, ebiten.InputChars()...)
@ -37,9 +36,11 @@ func update(screen *ebiten.Image) error {
} }
} }
counter++ counter++
if ebiten.IsRunningSlowly() { if ebiten.IsRunningSlowly() {
return nil return nil
} }
if counter%60 < 30 { if counter%60 < 30 {
return ebitenutil.DebugPrint(screen, string(append(runes, '_'))) return ebitenutil.DebugPrint(screen, string(append(runes, '_')))
} }
@ -47,5 +48,7 @@ func update(screen *ebiten.Image) error {
} }
func main() { func main() {
log.Fatal(ebiten.Run(update, 320, 240, 2.0, "Runes (Ebiten Demo)")) // ebiterm? if err := ebiten.Run(update, 320, 240, 2.0, "Runes (Ebiten Demo)"); err != nil {
log.Fatal(err)
}
} }