mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 19:28:57 +01:00
examples/blocks/blocks: Support standard gamepad axes
This commit is contained in:
parent
a7b5db6f65
commit
0d673a68ab
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user