inpututil: Add JustPressedTouches and remove IsJustTouched

Fixes #576
This commit is contained in:
Hajime Hoshi 2018-04-08 04:59:13 +09:00
parent 008ed26276
commit f1fa8804d3
2 changed files with 14 additions and 10 deletions

View File

@ -182,11 +182,8 @@ func jump() bool {
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) {
return true
}
if len(ebiten.Touches()) > 0 {
id := ebiten.Touches()[0].ID()
if inpututil.IsJustTouched(id) {
return true
}
if len(inpututil.JustPressedTouches()) > 0 {
return true
}
return false
}

View File

@ -249,12 +249,19 @@ func GamepadButtonPressDuration(id int, button ebiten.GamepadButton) int {
return s
}
// IsJustTouched returns a boolean value indicating
// whether the given touch is pressed just in the current frame.
// JustPressedTouches returns touch IDs that are created just in the current frame.
//
// IsJustTouched is concurrent safe.
func IsJustTouched(id int) bool {
return TouchDuration(id) == 1
// JustPressedTouches is concurrent safe.
func JustPressedTouches() []int {
ids := []int{}
theInputState.m.RLock()
for id, s := range theInputState.touchStates {
if s == 1 {
ids = append(ids, id)
}
}
theInputState.m.RUnlock()
return ids
}
// IsTouchJustReleased returns a boolean value indicating