From 18d23b5931e32a1bdfb747d32541ca15cbd6ffa9 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Wed, 7 Jun 2017 01:38:04 +0900 Subject: [PATCH] examples/blocks: gamepad configuration didn't work well with PS4 controllers --- examples/blocks/blocks/gamepad.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/examples/blocks/blocks/gamepad.go b/examples/blocks/blocks/gamepad.go index e6782baa0..b5527a23e 100644 --- a/examples/blocks/blocks/gamepad.go +++ b/examples/blocks/blocks/gamepad.go @@ -90,15 +90,19 @@ func (c *gamepadConfig) Scan(index int, b abstractButton) bool { an := ebiten.GamepadAxisNum(index) for a := 0; a < an; a++ { v := ebiten.GamepadAxis(index, a) - // Check v <= 1.0 because there is a bug that a button returns an axis value wrongly and the value may be over 1. - if threshold <= v && v <= 1.0 { + // Check |v| < 1.0 because + // 1) there is a bug that a button returns an axis value wrongly + // and the value may be over 1. + // 2) just 1.0 or -1.0 values are ignored since PS4's L2/R2 keys take + // -1.0 by default. + if threshold <= v && v < 1.0 { if _, ok := c.assignedAxes[axis{a, true}]; !ok { c.axes[b] = axis{a, true} c.assignedAxes[axis{a, true}] = struct{}{} return true } } - if -1.0 <= v && v <= -threshold { + if -1.0 < v && v <= -threshold { if _, ok := c.assignedAxes[axis{a, false}]; !ok { c.axes[b] = axis{a, false} c.assignedAxes[axis{a, false}] = struct{}{}