1.Overview
Game Controllers a core input device for gamers. With modern technology many browsers support gamepad input. Many desktop games come built with game controller input as an alternative to the keyboard and mouse. Of course, game consoles default to game controllers to process all user input. Most main stream game controllers include some sort of d-pad, four face buttons and one or two sets of shoulder buttons.
2.GameController Functions
bool gpe.gamepad_connected(int controllerNumber)
Returns true or false if the the controller in question is connected. All out of bound values return false as well.
Scope: GPE
Return type : bool
Parameters:
- int controllerNumber – the controller number(Typically ranges from 0 to 7 with 0 representing “player1”).
String gpe.gamepad_detected_name(int controllerNumber)
Returns the detected name for the controller device. Returns the detected device name(as defined by GPE standards).All out of bound values return an empty string.
Scope: GPE
Return type : String
Parameters:
- int controllerNumber – the controller number(Typically ranges from 0 to 7 with 0 representing “player1”).
String gpe.gamepad_name(int controllerNumber)
Returns the system name for the controller. Please note this often time varies by browser. All out of bound values return an empty string.
Scope: GPE
Return type : String
Parameters:
- int controllerNumber – the controller number(Typically ranges from 0 to 7 with 0 representing “player1”).
bool gpe.check_gamepad _down(int controllerNumber, int buttonId)
Returns true or false if the button is being pressed now.
Scope: GPE
Return type : bool
Parameters:
- int controllerNumber – the controller number(Typically ranges from 0 to 7 with 0 representing “player1”). If left as gc_anycontroller it will check all controllers with this function.
- int buttonId- The constant assigned to the button. Also processes the nobutton and anybutton cases.
float gpe.check_gamepad _pressed(int controllerNumber,int buttonId)
Returns true or false if the mouse button was just pressed in frame. For certain devices it will return the intensity the button has been pressed with.
Scope: GPE
Return type : float
Parameters:
- int controllerNumber – the controller number(Typically ranges from 0 to 7 with 0 representing “player1”). If left as gc_anycontroller it will check all controllers with this function.
- int buttonId- The constant assigned to the button. Also processes the nobutton and anybutton cases.
bool gpe.check_gamepad _released(int controllerNumber, int buttonId)
Returns true or false if the controller withwas just released in frame.
Scope: GPE
Return type : bool
Parameters:
- int controllerNumber – the controller number(Typically ranges from 0 to 7 with 0 representing “player1”). If left as gc_anycontroller it will check all controllers with this function.
- int buttonId- The constant assigned to the button. Also processes the nobutton and anybutton cases.
3.Game Controller Constants
In GPE we utilize constants with the “gc_” prefix for handling button input. It is important to know their importance when referencing buttons and their states throughout your games
Here is a complete list of the gc_ constants:
[table id=6 /]
4.Examples
Moving the player around with keyboard or gamepad input:
Placed inside of the player’s object “Main Logic” codeblock…
//Checks for the A button keyboard or left button on the gamepad if (gpe.check_keyboard(gp_a) || gpe.check_gamepad_down(0,gc_left) ) { this.move_left(4); } else if (gpe.check_keyboard(gp_d) || gpe.check_gamepad_down(0,gc_right) ) { this.move_right(4); } else if (gpe.check_keyboard(gp_w) || gpe.check_gamepad_down(0,gc_up) ) { this.move_up( 4); } else if (gpe.check_keyboard(gp_s) || gpe.check_gamepad_down(0,gc_down) ) { this.move_down(4); } //Centers the camera round the player object gpe.center_camera( 0,this.getx(), this.gety() );