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