All Bundles
GameController
Handles inputs from joysticks
Operations
New
Open a game controller for use.
New(joystick_index:Int)
Parameters
Name | Type | Description |
---|
joystick_index | Int | the device_index |
AddMapping
Add support for controllers that SDL is unaware of or to cause an existing controller to have a different binding
function : AddMapping(mapping_string:String) ~ Int
Parameters
Name | Type | Description |
---|
mapping_string | String | the mapping string |
Return
Type | Description |
---|
Int | 1 if a new mapping is added, 0 if an existing mapping is updated, -1 on error |
Close
Close a game controller previously opened
method : public : Close() ~ Nil
EventState
Query or change current state of Game Controller events
function : EventState(state:Int) ~ Int
Parameters
Name | Type | Description |
---|
state | Int | can be one of `SDL_QUERY`, `SDL_IGNORE`, or `SDL_ENABLE` |
Return
Type | Description |
---|
Int | the same value passed to the function, with exception to -1, which will return the current state |
FromInstanceID
Get the SDL_GameController associated with an instance id
function : FromInstanceID(joyid:Int) ~ GameController
Parameters
Name | Type | Description |
---|
joyid | Int | the instance id to get the SDL_GameController for |
Return
Type | Description |
---|
GameController | an SDL_GameController on success or NULL on failure |
GetAttached
Check if a controller has been opened and is currently connected.
method : public : GetAttached() ~ Bool
Return
Type | Description |
---|
Bool | true if the controller has been opened and is currently connected, or false if not |
GetAxis
Get the current state of an axis control on a game controller
method : public : GetAxis(axis:GameControllerAxis) ~ Int
Parameters
Name | Type | Description |
---|
axis | GameControllerAxis | an axis index (one of the SDL_GameControllerAxis values) |
Return
Type | Description |
---|
Int | axis state (including 0) on success or 0 (also) on failure |
GetAxisFromString
Convert a string into SDL_GameControllerAxis enum
function : GetAxisFromString(str:String) ~ GameControllerAxis
Parameters
Name | Type | Description |
---|
str | String | string representing a SDL_GameController axis |
Return
Type | Description |
---|
GameControllerAxis | the GameControllerAxis enum corresponding to the input string, or SDL_CONTROLLER_AXIS_INVALID if no match was found. |
GetBindForAxis
Get the SDL joystick layer binding for a controller axis mapping
method : public : GetBindForAxis(axis:GameControllerAxis) ~ GameControllerButtonBind
Parameters
Name | Type | Description |
---|
axis | GameControllerAxis | an axis enum value (one of the SDL_GameControllerAxis values) |
Return
GetBindForButton
Get the SDL joystick layer binding for a controller button mapping
method : public : GetBindForButton(button:GameControllerButton) ~ GameControllerButtonBind
Parameters
Name | Type | Description |
---|
button | GameControllerButton | an button enum value (an SDL_GameControllerButton value) |
Return
GetButton
Get the current state of a button on a game controller
method : public : GetButton(button:GameControllerButton) ~ Int
Parameters
Name | Type | Description |
---|
button | GameControllerButton | a button index (one of the SDL_GameControllerButton values) |
Return
Type | Description |
---|
Int | 1 for pressed state or 0 for not pressed state or error |
GetButtonFromString
Convert a string into an SDL_GameControllerButton enum
function : GetButtonFromString(str:String) ~ GameControllerButton
Parameters
Name | Type | Description |
---|
str | String | string representing a SDL_GameController axis |
Return
Type | Description |
---|
GameControllerButton | the SDL_GameControllerButton enum corresponding to the input string |
GetJoystick
This function will give you a SDL_Joystick object, which allows you to use the SDL_Joystick functions with a SDL_GameController object
method : public : GetJoystick() ~ Joystick
Return
Type | Description |
---|
Joystick | a Joystick object |
GetNumTouchpads
Get the number of touchpads on a game controller.
method : public : GetNumTouchpads() ~ Int
GetPlayerIndex
Get the player index of an opened game controller
method : public : GetPlayerIndex() ~ Int
Return
Type | Description |
---|
Int | the player index for controller, or -1 if it's not available |
GetProduct
Get the USB product ID of an opened controller, if available
method : public : GetProduct() ~ Int
Return
Type | Description |
---|
Int | the USB product ID, or zero if unavailable |
GetProductVersion
Get the product version of an opened controller, if available. If the product version isn't available this function returns 0.
method : public : GetProductVersion() ~ Int
Return
Type | Description |
---|
Int | the USB product version, or zero if unavailable |
GetStringForAxis
Convert from an SDL_GameControllerAxis enum to a string
function : GetStringForAxis(axis:GameControllerAxis) ~ String
Parameters
Return
Type | Description |
---|
String | string for the given axis, or Nil if an invalid axis is specified |
GetStringForButton
Convert from an SDL_GameControllerButton enum to a string
function : GetStringForButton(button:GameControllerButton) ~ String
Parameters
Return
Type | Description |
---|
String | a string for the given button |
GetVendor
Get the USB vendor ID of an opened controller, if available
method : public : GetVendor() ~ Int
Return
Type | Description |
---|
Int | the USB vendor ID, or zero if unavailable |
IsController
Check if the given joystick is supported by the game controller interface
function : IsController(joystick_index:Int) ~ Bool
Parameters
Name | Type | Description |
---|
joystick_index | Int | the device_index of a device |
Return
Type | Description |
---|
Bool | joystick_index the device_index of a device |
Mapping
Get the current mapping of a Game Controller
method : public : Mapping() ~ String
Return
Type | Description |
---|
String | string that has the controller's mapping or NULL if no mapping is available |
Name
Get the SDL_GameController associated with an instance id
method : public : Name() ~ String
Return
Type | Description |
---|
String | an SDL_GameController on success or NULL on failure |
NameForIndex
Get the implementation dependent name for the game controller
function : NameForIndex(joystick_index:Int) ~ String
Parameters
Name | Type | Description |
---|
joystick_index | Int | the device_index of a device |
Return
Type | Description |
---|
String | joystick_index the device_index of a device |
NumMappings
Get the number of mappings installed
function : NumMappings() ~ Int
Return
Type | Description |
---|
Int | the number of mappings |
Rumble
Start a rumble effect on a game controller
method : public : Rumble(low_frequency_rumble:Int, high_frequency_rumble:Int, duration_ms:Int) ~ Int
Parameters
Name | Type | Description |
---|
low_frequency_rumble | Int | The intensity of the low frequency (left) rumble motor, from 0 to 0xFFFF |
high_frequency_rumble | Int | The intensity of the high frequency (right) rumble motor, from 0 to 0xFFFF |
duration_ms | Int | The duration of the rumble effect, in milliseconds |
Return
Type | Description |
---|
Int | 0, or -1 if rumble isn't supported on this controller |
Update
Manually pump game controller updates if not using the loop.
function : Update() ~ Nil