From 0d673a68ab4d53d6bd59e69e07b8763372207531 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 24 Sep 2021 23:35:01 +0900 Subject: [PATCH] examples/blocks/blocks: Support standard gamepad axes --- examples/blocks/blocks/gamepad.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/examples/blocks/blocks/gamepad.go b/examples/blocks/blocks/gamepad.go index b2643ff0b..d311e3328 100644 --- a/examples/blocks/blocks/gamepad.go +++ b/examples/blocks/blocks/gamepad.go @@ -196,7 +196,20 @@ func (c *gamepadConfig) IsButtonPressed(b virtualGamepadButton) bool { } if ebiten.IsStandardGamepadLayoutAvailable(c.gamepadID) { - return ebiten.IsStandardGamepadButtonPressed(c.gamepadID, b.StandardGamepadButton()) + if ebiten.IsStandardGamepadButtonPressed(c.gamepadID, b.StandardGamepadButton()) { + return true + } + + const threshold = 0.7 + switch b { + case virtualGamepadButtonLeft: + return ebiten.StandardGamepadAxisValue(c.gamepadID, ebiten.StandardGamepadAxisLeftStickHorizontal) < -threshold + case virtualGamepadButtonRight: + return ebiten.StandardGamepadAxisValue(c.gamepadID, ebiten.StandardGamepadAxisLeftStickHorizontal) > threshold + case virtualGamepadButtonDown: + return ebiten.StandardGamepadAxisValue(c.gamepadID, ebiten.StandardGamepadAxisLeftStickVertical) > threshold + } + return false } c.initializeIfNeeded()