mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +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) {
|
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()
|
c.initializeIfNeeded()
|
||||||
|
Loading…
Reference in New Issue
Block a user