Difference between revisions of "love.joystick.setGamepadMapping"

(Add suffix bug notice)
m
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{newin|[[0.9.0]]|090|type=function}}
+
{{newin|[[0.9.2]]|092|type=function}}
{{notice|Due to a bug, any mapping that is a suffix of another (for example "x" is a suffix to "leftx") needs to be mapped first}}
 
 
Binds a virtual gamepad input to a button, axis or hat for all Joysticks of a certain type. For example, if this function is used with a [[Joystick:getGUID|GUID]] returned by a Dualshock 3 controller in OS X, the binding will affect [[Joystick:getGamepadAxis]] and [[Joystick:isGamepadDown]] for ''all'' Dualshock 3 controllers used with the game when run in OS X.
 
Binds a virtual gamepad input to a button, axis or hat for all Joysticks of a certain type. For example, if this function is used with a [[Joystick:getGUID|GUID]] returned by a Dualshock 3 controller in OS X, the binding will affect [[Joystick:getGamepadAxis]] and [[Joystick:isGamepadDown]] for ''all'' Dualshock 3 controllers used with the game when run in OS X.
  
Line 15: Line 14:
 
{{param|GamepadButton|button|The virtual gamepad button to bind.}}
 
{{param|GamepadButton|button|The virtual gamepad button to bind.}}
 
{{param|JoystickInputType|inputtype|The type of input to bind the virtual gamepad button to.}}
 
{{param|JoystickInputType|inputtype|The type of input to bind the virtual gamepad button to.}}
{{param|number|inputindex|The index of the axis, button, or hat to bind the virtual gamepad button to.}}
+
{{param|number|inputindex|The 1-based index of the axis, button, or hat to bind the virtual gamepad button to.}}
 
{{param|JoystickHat|hatdir (nil)|The direction of the hat, if the virtual gamepad button will be bound to a hat. nil otherwise.}}
 
{{param|JoystickHat|hatdir (nil)|The direction of the hat, if the virtual gamepad button will be bound to a hat. nil otherwise.}}
 
=== Returns ===
 
=== Returns ===
Line 29: Line 28:
 
{{param|GamepadAxis|axis|The virtual gamepad axis to bind.}}
 
{{param|GamepadAxis|axis|The virtual gamepad axis to bind.}}
 
{{param|JoystickInputType|inputtype|The type of input to bind the virtual gamepad axis to.}}
 
{{param|JoystickInputType|inputtype|The type of input to bind the virtual gamepad axis to.}}
{{param|number|inputindex|The index of the axis, button, or hat to bind the virtual gamepad axis to.}}
+
{{param|number|inputindex|The 1-based index of the axis, button, or hat to bind the virtual gamepad axis to.}}
 
{{param|JoystickHat|hatdir (nil)|The direction of the hat, if the virtual gamepad axis will be bound to a hat. nil otherwise.}}
 
{{param|JoystickHat|hatdir (nil)|The direction of the hat, if the virtual gamepad axis will be bound to a hat. nil otherwise.}}
 
=== Returns ===
 
=== Returns ===
Line 35: Line 34:
  
 
== Notes ==
 
== Notes ==
 +
LÖVE versions older than [[0.10.0]] have a bug which requires any mapping that is a suffix of another (for example "x" is a suffix to "leftx") to be mapped first.
 +
 
The physical locations for the bound gamepad axes and buttons should correspond as closely as possible to the layout of a standard Xbox 360 controller.
 
The physical locations for the bound gamepad axes and buttons should correspond as closely as possible to the layout of a standard Xbox 360 controller.
  

Latest revision as of 14:53, 18 June 2023

Available since LÖVE 0.9.2
This function is not supported in earlier versions.

Binds a virtual gamepad input to a button, axis or hat for all Joysticks of a certain type. For example, if this function is used with a GUID returned by a Dualshock 3 controller in OS X, the binding will affect Joystick:getGamepadAxis and Joystick:isGamepadDown for all Dualshock 3 controllers used with the game when run in OS X.

LÖVE includes built-in gamepad bindings for many common controllers. This function lets you change the bindings or add new ones for types of Joysticks which aren't recognized as gamepads by default.

The virtual gamepad buttons and axes are designed around the Xbox 360 controller layout.

Function

Synopsis

success = love.joystick.setGamepadMapping( guid, button, inputtype, inputindex, hatdir )

Arguments

string guid
The OS-dependent GUID for the type of Joystick the binding will affect.
GamepadButton button
The virtual gamepad button to bind.
JoystickInputType inputtype
The type of input to bind the virtual gamepad button to.
number inputindex
The 1-based index of the axis, button, or hat to bind the virtual gamepad button to.
JoystickHat hatdir (nil)
The direction of the hat, if the virtual gamepad button will be bound to a hat. nil otherwise.

Returns

boolean success
Whether the virtual gamepad button was successfully bound.

Function

Synopsis

success = love.joystick.setGamepadMapping( guid, axis, inputtype, inputindex, hatdir )

Arguments

string guid
The OS-dependent GUID for the type of Joystick the binding will affect.
GamepadAxis axis
The virtual gamepad axis to bind.
JoystickInputType inputtype
The type of input to bind the virtual gamepad axis to.
number inputindex
The 1-based index of the axis, button, or hat to bind the virtual gamepad axis to.
JoystickHat hatdir (nil)
The direction of the hat, if the virtual gamepad axis will be bound to a hat. nil otherwise.

Returns

boolean success
Whether the virtual gamepad axis was successfully bound.

Notes

LÖVE versions older than 0.10.0 have a bug which requires any mapping that is a suffix of another (for example "x" is a suffix to "leftx") to be mapped first.

The physical locations for the bound gamepad axes and buttons should correspond as closely as possible to the layout of a standard Xbox 360 controller.

360 controller.png

See Also

Other Languages