mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 20:18:59 +01:00
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.
This commit is contained in:
parent
0fcf5c8470
commit
0300be7d9e
@ -47,9 +47,11 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Game struct {
|
type Game struct {
|
||||||
|
keys []ebiten.Key
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Game) Update() error {
|
func (g *Game) Update() error {
|
||||||
|
g.keys = inpututil.PressedKeys()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,8 +69,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
|
|||||||
|
|
||||||
// Draw the highlighted keys.
|
// Draw the highlighted keys.
|
||||||
op = &ebiten.DrawImageOptions{}
|
op = &ebiten.DrawImageOptions{}
|
||||||
keys := inpututil.PressedKeys()
|
for _, p := range g.keys {
|
||||||
for _, p := range keys {
|
|
||||||
op.GeoM.Reset()
|
op.GeoM.Reset()
|
||||||
r, ok := keyboard.KeyRect(p)
|
r, ok := keyboard.KeyRect(p)
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -80,7 +81,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
keyStrs := []string{}
|
keyStrs := []string{}
|
||||||
for _, p := range keys {
|
for _, p := range g.keys {
|
||||||
keyStrs = append(keyStrs, p.String())
|
keyStrs = append(keyStrs, p.String())
|
||||||
}
|
}
|
||||||
ebitenutil.DebugPrint(screen, strings.Join(keyStrs, ", "))
|
ebitenutil.DebugPrint(screen, strings.Join(keyStrs, ", "))
|
||||||
|
Loading…
Reference in New Issue
Block a user