diff --git a/examples/blocks/blocks/gamepad.go b/examples/blocks/blocks/gamepad.go index a2d7693be..8fba580d8 100644 --- a/examples/blocks/blocks/gamepad.go +++ b/examples/blocks/blocks/gamepad.go @@ -59,7 +59,7 @@ func (v virtualGamepadButton) StandardGamepadButton() ebiten.StandardGamepadButt const axisThreshold = 0.75 type axis struct { - id int + id ebiten.GamepadAxisType positive bool } @@ -73,7 +73,7 @@ type gamepadConfig struct { assignedButtons map[ebiten.GamepadButton]struct{} assignedAxes map[axis]struct{} - defaultAxesValues map[int]float64 + defaultAxesValues map[ebiten.GamepadAxisType]float64 } func (c *gamepadConfig) SetGamepadID(id ebiten.GamepadID) { @@ -122,9 +122,9 @@ func (c *gamepadConfig) initializeIfNeeded() { // These default values are used to detect if an axis is actually pressed. // For example, on PS4 controllers, L2/R2's axes value can be -1.0. if c.defaultAxesValues == nil { - c.defaultAxesValues = map[int]float64{} - na := ebiten.GamepadAxisCount(c.gamepadID) - for a := 0; a < na; a++ { + c.defaultAxesValues = map[ebiten.GamepadAxisType]float64{} + na := ebiten.GamepadAxisType(ebiten.GamepadAxisCount(c.gamepadID)) + for a := ebiten.GamepadAxisType(0); a < na; a++ { c.defaultAxesValues[a] = ebiten.GamepadAxisValue(c.gamepadID, a) } } @@ -161,8 +161,8 @@ func (c *gamepadConfig) Scan(b virtualGamepadButton) bool { } } - na := ebiten.GamepadAxisCount(c.gamepadID) - for a := 0; a < na; a++ { + na := ebiten.GamepadAxisType(ebiten.GamepadAxisCount(c.gamepadID)) + for a := ebiten.GamepadAxisType(0); a < na; a++ { v := ebiten.GamepadAxisValue(c.gamepadID, a) const delta = 0.25 diff --git a/examples/gamepad/main.go b/examples/gamepad/main.go index fbf321e5c..64628a288 100644 --- a/examples/gamepad/main.go +++ b/examples/gamepad/main.go @@ -60,8 +60,8 @@ func (g *Game) Update() error { g.axes = map[ebiten.GamepadID][]string{} g.pressedButtons = map[ebiten.GamepadID][]string{} for id := range g.gamepadIDs { - maxAxis := ebiten.GamepadAxisCount(id) - for a := 0; a < maxAxis; a++ { + maxAxis := ebiten.GamepadAxisType(ebiten.GamepadAxisCount(id)) + for a := ebiten.GamepadAxisType(0); a < maxAxis; a++ { v := ebiten.GamepadAxisValue(id, a) g.axes[id] = append(g.axes[id], fmt.Sprintf("%d:%+0.2f", a, v)) } diff --git a/gamepad.go b/gamepad.go index 30c8db66e..42adf3ccc 100644 --- a/gamepad.go +++ b/gamepad.go @@ -59,6 +59,10 @@ const ( GamepadButtonMax GamepadButton = GamepadButton31 ) +// GamepadAxisType represents a gamepad axis. +// This is the same as int for backward compatibility in v2. +type GamepadAxisType = int + // StandardGamepadButton represents a gamepad button in the standard layout. // // The layout and the button values are based on the web standard. diff --git a/input.go b/input.go index 315a48033..3b98dd3b9 100644 --- a/input.go +++ b/input.go @@ -180,18 +180,18 @@ func GamepadAxisNum(id GamepadID) int { // GamepadAxisValue returns a float value [-1.0 - 1.0] of the given gamepad (id)'s axis (axis). // // GamepadAxisValue is concurrent-safe. -func GamepadAxisValue(id GamepadID, axis int) float64 { +func GamepadAxisValue(id GamepadID, axis GamepadAxisType) float64 { g := gamepad.Get(id) if g == nil { return 0 } - return g.Axis(axis) + return g.Axis(int(axis)) } // GamepadAxis returns a float value [-1.0 - 1.0] of the given gamepad (id)'s axis (axis). // // Deprecated: as of v2.2. Use GamepadAxisValue instead. -func GamepadAxis(id GamepadID, axis int) float64 { +func GamepadAxis(id GamepadID, axis GamepadAxisType) float64 { return GamepadAxisValue(id, axis) }