mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
examples/piano: Use inpututil (#415)
This commit is contained in:
parent
2772f8d990
commit
67ebf848e7
@ -29,6 +29,7 @@ import (
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/audio"
|
||||
"github.com/hajimehoshi/ebiten/ebitenutil"
|
||||
"github.com/hajimehoshi/ebiten/inpututil"
|
||||
"github.com/hajimehoshi/ebiten/text"
|
||||
)
|
||||
|
||||
@ -209,20 +210,8 @@ var (
|
||||
ebiten.KeyO,
|
||||
ebiten.KeyL,
|
||||
}
|
||||
keyStates = map[ebiten.Key]int{}
|
||||
)
|
||||
|
||||
// updateInput updates the input state.
|
||||
func updateInput() {
|
||||
for _, key := range keys {
|
||||
if !ebiten.IsKeyPressed(key) {
|
||||
keyStates[key] = 0
|
||||
continue
|
||||
}
|
||||
keyStates[key]++
|
||||
}
|
||||
}
|
||||
|
||||
func update(screen *ebiten.Image) error {
|
||||
// The piano data is still being initialized.
|
||||
// Get the progress if available.
|
||||
@ -235,9 +224,8 @@ func update(screen *ebiten.Image) error {
|
||||
}
|
||||
|
||||
if pianoNoteSamplesInited {
|
||||
updateInput()
|
||||
for i, key := range keys {
|
||||
if keyStates[key] != 1 {
|
||||
if !inpututil.IsKeyJustPressed(key) {
|
||||
continue
|
||||
}
|
||||
playNote(baseFreq * math.Exp2(float64(i-1)/12.0))
|
||||
|
Loading…
Reference in New Issue
Block a user