GameController Input

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:

ConstantDescription
gc_anybuttonUsed to check for any button on the controller.
gc_anobuttonUsed to check for all buttons being unused.
gc_leftThe left button(typically seen on the D-pad)
gc_rightThe right button(typically seen on the D-pad)
gc_upThe up button(typically seen on the D-pad)
gc_downThe down button(typically seen on the D-pad)
gc_but0The main button on the controller usually also known as "A" on the Xbox/Nintendo Systems and the cross button on the Playstation controllers.
gc_but1The cancel button on the controller usually also known as "B" on the Xbox/Nintendo Systems and the circle button on the Playstation controllers.
gc_but2The secondary action button on the controller usually also known as "X" on the Xbox/Nintendo Systems and the square button on the Playstation controllers.
gc_but3The back button on the controller usually also known as "Y" on the Xbox/Nintendo Systems and the triangle button on the Playstation controllers.
gc_l1The left shoulder button on systems with only one set of shoulder buttons. On other controllers it is the front-shoulder left button on mainstream consoles.
gc_l2The back left shoulder button on controllers that support it. On the Dullshock4 it is named LT.
gc_l3This button is activated by pressing the left joystick.
gc_r1The right shoulder button on systems with only one set of shoulder buttons. On other controllers it is the front-shoulder right button on mainstream consoles.
gc_r2The back right shoulder button on controllers that support it. On the Dullshock4 it is named RT.
gc_r3This button is activated by pressing the right joystick.
gc_selectThe select button is the touchpad on the PS4 controller and "+" on Nintendo controllers since the Wii era.


gc_startThe start button is the options button on the PS4 controller and "+" on Nintendo controllers since the Wii era.
gc_homeThis button is typically called the "Home/Console" button.
gc_shareThis button is typically used to print screenshots and/or record videos.
gc_joystick_left_xThe x-axis for the left joystick on most modern controllers.
gc_joystick_left_yThe y-axis for the left joystick on most modern controllers.
gc_joystick_right_xThe x-axis for the right joystick on most modern controllers.
gc_joystick_right_yThe y-axis for the right joystick on most modern controllers.
gc_joystick_dpad_xThe x-axis that represents the d-pad on some game controllers.
gc_joystick_dpad_yThe y-axis that represents the d-pad on some game controllers.

4.Examples

Moving the player around with keyboard or gamepad input:

Placed inside of the player’s object “Main Logic” codeblock…

 

Suggest Edit