mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
examples/typewriter: Enable backspace
This commit is contained in:
parent
cea9bd5a19
commit
cd70bc039b
@ -25,8 +25,9 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
text = "Type on the keyboard:\n"
|
||||
counter = 0
|
||||
text = "Type on the keyboard:\n"
|
||||
counter = 0
|
||||
bsPrevPressed = false
|
||||
)
|
||||
|
||||
func update(screen *ebiten.Image) error {
|
||||
@ -38,6 +39,13 @@ func update(screen *ebiten.Image) error {
|
||||
if ebiten.IsKeyPressed(ebiten.KeyEnter) && !strings.HasSuffix(text, "\n") {
|
||||
text += "\n"
|
||||
}
|
||||
bsPressed := ebiten.IsKeyPressed(ebiten.KeyBackspace)
|
||||
if !bsPrevPressed && bsPressed {
|
||||
if len(text) >= 1 {
|
||||
text = text[:len(text)-1]
|
||||
}
|
||||
}
|
||||
bsPrevPressed = bsPressed
|
||||
|
||||
counter++
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user