From 0300be7d9ee757f10af23bd8a881b40078882c3c Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Wed, 7 Apr 2021 01:54:47 +0900 Subject: [PATCH] examples/keyboard: Use inpututil functions in Update rather than Draw This is not a strict rule, but it is preferrable to use input functions in Update rather than Draw. --- examples/keyboard/main.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/keyboard/main.go b/examples/keyboard/main.go index 77a2c9a3a..058479a83 100644 --- a/examples/keyboard/main.go +++ b/examples/keyboard/main.go @@ -47,9 +47,11 @@ func init() { } type Game struct { + keys []ebiten.Key } func (g *Game) Update() error { + g.keys = inpututil.PressedKeys() return nil } @@ -67,8 +69,7 @@ func (g *Game) Draw(screen *ebiten.Image) { // Draw the highlighted keys. op = &ebiten.DrawImageOptions{} - keys := inpututil.PressedKeys() - for _, p := range keys { + for _, p := range g.keys { op.GeoM.Reset() r, ok := keyboard.KeyRect(p) if !ok { @@ -80,7 +81,7 @@ func (g *Game) Draw(screen *ebiten.Image) { } keyStrs := []string{} - for _, p := range keys { + for _, p := range g.keys { keyStrs = append(keyStrs, p.String()) } ebitenutil.DebugPrint(screen, strings.Join(keyStrs, ", "))