mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 12:08:58 +01:00
examples/typewriter: Refactoring: Use inpututil
This commit is contained in:
parent
fac7651152
commit
54bec7a3eb
@ -22,12 +22,12 @@ import (
|
|||||||
|
|
||||||
"github.com/hajimehoshi/ebiten"
|
"github.com/hajimehoshi/ebiten"
|
||||||
"github.com/hajimehoshi/ebiten/ebitenutil"
|
"github.com/hajimehoshi/ebiten/ebitenutil"
|
||||||
|
"github.com/hajimehoshi/ebiten/inpututil"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
text = "Type on the keyboard:\n"
|
text = "Type on the keyboard:\n"
|
||||||
counter = 0
|
counter = 0
|
||||||
bsPrevPressed = false
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func update(screen *ebiten.Image) error {
|
func update(screen *ebiten.Image) error {
|
||||||
@ -43,18 +43,16 @@ func update(screen *ebiten.Image) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If the enter key is pressed, add a line break.
|
// If the enter key is pressed, add a line break.
|
||||||
if ebiten.IsKeyPressed(ebiten.KeyEnter) && !strings.HasSuffix(text, "\n") {
|
if inpututil.IsKeyJustPressed(ebiten.KeyEnter) || inpututil.IsKeyJustPressed(ebiten.KeyKPEnter) {
|
||||||
text += "\n"
|
text += "\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the backspace key is pressed, remove one character.
|
// If the backspace key is pressed, remove one character.
|
||||||
bsPressed := ebiten.IsKeyPressed(ebiten.KeyBackspace)
|
if inpututil.IsKeyJustPressed(ebiten.KeyBackspace) {
|
||||||
if !bsPrevPressed && bsPressed {
|
|
||||||
if len(text) >= 1 {
|
if len(text) >= 1 {
|
||||||
text = text[:len(text)-1]
|
text = text[:len(text)-1]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bsPrevPressed = bsPressed
|
|
||||||
|
|
||||||
counter++
|
counter++
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user