mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
input: Add GamepadButtonMax
This commit is contained in:
parent
623fa5cd24
commit
d62a90dfca
@ -28,7 +28,7 @@ var gamepadAbstractButtons = []abstractButton{
|
||||
|
||||
type Input struct {
|
||||
keyStates [256]int
|
||||
gamepadButtonStates [256]int
|
||||
gamepadButtonStates map[ebiten.GamepadButton]int
|
||||
gamepadAbstractButtonStates map[abstractButton]int
|
||||
gamepadConfig gamepadConfig
|
||||
}
|
||||
@ -38,6 +38,9 @@ func (i *Input) StateForKey(key ebiten.Key) int {
|
||||
}
|
||||
|
||||
func (i *Input) StateForGamepadButton(b ebiten.GamepadButton) int {
|
||||
if i.gamepadButtonStates == nil {
|
||||
return 0
|
||||
}
|
||||
return i.gamepadButtonStates[b]
|
||||
}
|
||||
|
||||
@ -58,8 +61,11 @@ func (i *Input) Update() {
|
||||
}
|
||||
|
||||
const gamepadID = 0
|
||||
for b := range i.gamepadButtonStates {
|
||||
if !ebiten.IsGamepadButtonPressed(gamepadID, ebiten.GamepadButton(b)) {
|
||||
if i.gamepadButtonStates == nil {
|
||||
i.gamepadButtonStates = map[ebiten.GamepadButton]int{}
|
||||
}
|
||||
for b := ebiten.GamepadButton(0); b <= ebiten.GamepadButtonMax; b++ {
|
||||
if !ebiten.IsGamepadButtonPressed(gamepadID, b) {
|
||||
i.gamepadButtonStates[b] = 0
|
||||
continue
|
||||
}
|
||||
|
@ -39,4 +39,5 @@ const (
|
||||
GamepadButton13 = GamepadButton(ui.GamepadButton13)
|
||||
GamepadButton14 = GamepadButton(ui.GamepadButton14)
|
||||
GamepadButton15 = GamepadButton(ui.GamepadButton15)
|
||||
GamepadButtonMax = GamepadButton15
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user