ebiten: Add GamepadAxisValue replacing GamepadAxis

Updates #1718
Closes #1719
This commit is contained in:
Hajime Hoshi 2021-07-19 01:22:31 +09:00
parent bd5cc145df
commit dbcb220742
5 changed files with 15 additions and 8 deletions

View File

@ -169,13 +169,20 @@ func GamepadAxisNum(id GamepadID) int {
return uiDriver().Input().GamepadAxisNum(id) return uiDriver().Input().GamepadAxisNum(id)
} }
// GamepadAxisValue returns the float value [-1.0 - 1.0] of the given gamepad (id)'s axis (axis).
//
// GamepadAxisValue is concurrent-safe.
//
// GamepadAxisValue always returns 0 on iOS.
func GamepadAxisValue(id GamepadID, axis int) float64 {
return uiDriver().Input().GamepadAxisValue(id, axis)
}
// GamepadAxis returns the float value [-1.0 - 1.0] of the given gamepad (id)'s axis (axis). // GamepadAxis returns the float value [-1.0 - 1.0] of the given gamepad (id)'s axis (axis).
// //
// GamepadAxis is concurrent-safe. // Deprecated: as of v2.2. Use GamepadAxisValue instead.
//
// GamepadAxis always returns 0 on iOS.
func GamepadAxis(id GamepadID, axis int) float64 { func GamepadAxis(id GamepadID, axis int) float64 {
return uiDriver().Input().GamepadAxis(id, axis) return GamepadAxisValue(id, axis)
} }
// GamepadButtonNum returns the number of the buttons of the given gamepad (id). // GamepadButtonNum returns the number of the buttons of the given gamepad (id).

View File

@ -25,7 +25,7 @@ type Input interface {
CursorPosition() (x, y int) CursorPosition() (x, y int)
GamepadSDLID(id GamepadID) string GamepadSDLID(id GamepadID) string
GamepadName(id GamepadID) string GamepadName(id GamepadID) string
GamepadAxis(id GamepadID, axis int) float64 GamepadAxisValue(id GamepadID, axis int) float64
GamepadAxisNum(id GamepadID) int GamepadAxisNum(id GamepadID) int
GamepadButtonNum(id GamepadID) int GamepadButtonNum(id GamepadID) int
IsGamepadButtonPressed(id GamepadID, button GamepadButton) bool IsGamepadButtonPressed(id GamepadID, button GamepadButton) bool

View File

@ -121,7 +121,7 @@ func (i *Input) GamepadAxisNum(id driver.GamepadID) int {
return i.gamepads[id].axisNum return i.gamepads[id].axisNum
} }
func (i *Input) GamepadAxis(id driver.GamepadID, axis int) float64 { func (i *Input) GamepadAxisValue(id driver.GamepadID, axis int) float64 {
if !i.ui.isRunning() { if !i.ui.isRunning() {
return 0 return 0
} }

View File

@ -129,7 +129,7 @@ func (i *Input) GamepadAxisNum(id driver.GamepadID) int {
return g.axisNum return g.axisNum
} }
func (i *Input) GamepadAxis(id driver.GamepadID, axis int) float64 { func (i *Input) GamepadAxisValue(id driver.GamepadID, axis int) float64 {
g, ok := i.gamepads[id] g, ok := i.gamepads[id]
if !ok { if !ok {
return 0 return 0

View File

@ -87,7 +87,7 @@ func (i *Input) GamepadAxisNum(id driver.GamepadID) int {
return 0 return 0
} }
func (i *Input) GamepadAxis(id driver.GamepadID, axis int) float64 { func (i *Input) GamepadAxisValue(id driver.GamepadID, axis int) float64 {
i.ui.m.RLock() i.ui.m.RLock()
defer i.ui.m.RUnlock() defer i.ui.m.RUnlock()