From cd70bc039b882b4aa8eaba76599a6833bbff4f62 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 10 Nov 2017 01:27:43 +0900 Subject: [PATCH] examples/typewriter: Enable backspace --- examples/typewriter/main.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/examples/typewriter/main.go b/examples/typewriter/main.go index 17b863647..885b9cf72 100644 --- a/examples/typewriter/main.go +++ b/examples/typewriter/main.go @@ -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++