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