Experimental Editor with AGS with Gamepad support!Download Editor Here: >>
AGS-3.6.0.25-Beta5-Gamepad-v4.zip<< |
Code Source |
GitHub IssueHere's just a gamepad check, running in the browser:
gamepad_check web exampleHere's the AGS Game Project of the above:
GamepadExample-v3.zipok, this is going to take
a long time, but hopefully we can figure out an API that is alright. The above editor adds a new struct in AGS, which is a Gamepad! A Gamepad maps different types of joysticks to the good old Xbox 360 controller.
I plan to later support manually figuring the joystick by querying every piece of it, which will be named a RawGamepad, which SDL2 names as joysticks, but if you have no idea what you are doing, Gamepad should be fine.
Gamepad Static MethodsGamepad.GetCountstatic int Gamepad.GetCount()
Get the number of connected joysticks. No joysticks should return 0!
Gamepad.Openstatic Gamepad* Gamepad.Open(int index)
Attempts to open a gamepad, returns null if it's not a valid gamepad! If a joystick is way too different from a Xbox360 this could fail too.
This is how you can connect to a Gamepad, you pass an index, which corresponds to the number of the joystick - if you actually have a Xbox360 Joystick, it's the green light.
Gamepad.GetNamestatic String Gamepad.GetName(int index)
If the index is a valid gamepad, get it's name!
Gamepad Instance Attributes and MethodsGamepad.IsConnectedbool Gamepad.IsConnected()
True if gamepad is really connected.
Gamepad.IsButtonDownbool Gamepad.IsButtonDown(eGamepad_Button button)
checks if a gamepad button is pressed, including dpad.
Possible buttons:
- eGamepad_ButtonA
- eGamepad_ButtonB
- eGamepad_ButtonX
- eGamepad_ButtonY
- eGamepad_ButtonBack
- eGamepad_ButtonGuide
- eGamepad_ButtonStart
- eGamepad_ButtonLeftStick
- eGamepad_ButtonRightStick
- eGamepad_ButtonLeftShoulder
- eGamepad_ButtonRightShoulder
- eGamepad_ButtonDpadUp
- eGamepad_ButtonDpadDown
- eGamepad_ButtonDpadLeft
- eGamepad_ButtonDpadRight
Gamepad.GetAxisfloat Gamepad.GetAxis(eGamepad_Axis axis, optional float deadzone)
get gamepad axis or trigger, trigger only has positive values. Values varies from -1.0 to 1.0 for axis, and 0.0 to 1.0 for triggers.
You can optionally pass an additional parameter to use as deadzone. If an axis absolute value is smaller than the value of deadzone, it will return 0.0. Default value is GAMEPAD_DEFAULT_DEADZONE, which is for now 0.125, use the name if you need a number.
Possible axis and triggers:
- eGamepad_AxisLeftX
- eGamepad_AxisLeftY
- eGamepad_AxisRightX
- eGamepad_AxisRightY
- eGamepad_AxisTriggerLeft
- eGamepad_AxisTriggerRight
Gamepad.Namereadonly String Gamepad.Name
gamepad name.
CHANGELOG:- v1: initial release
- v2: GetAxis now returns a float
- v3: GetAxis now has an additional dead_zone parameter. Default value is GAMEPAD_DEFAULT_DEADZONE, which is for now 0.125, use the name if you need a number.
- v4: Using correspondent A,B,X,Y buttons can skip Speech and Display messages, as long as you Connect to the Gamepad.