Provides support for reading state-based game controllers.

Use the Controller class to read the state of game controllers that are recognised by the operating system.

Unlike analog devices that stream input commands (e.g. mice), gamepad controllers maintain a state that can be read at any time. The controller state is normally read at least once per frame, which can be achieved in the main inner loop, or in a separate timer.

Controller input management is governed by the Display class. The GRAB_CONTROLLERS flag must be defined in the active Display's Flags field in order to ensure that controller input can be received. Failure to do so may mean that the Controller object appears to work but does not receive input.

Structure

The Controller class consists of the following fields:

Access
NameTypeComment
  ButtonsCONJET button values expressed as bit-fields.
NameDescription
  LeftStickXDOUBLELeft analog stick value for X axis, between -1.0 and 1.0.
  LeftStickYDOUBLELeft analog stick value for Y axis, between -1.0 and 1.0.
  LeftTriggerDOUBLELeft trigger value between 0.0 and 1.0.
  PortINTThe port number assigned to the controller.

Set the port number to choose the controller that will be queried for state changes. The default of zero is assigned to the primary controller.

The port number can be changed at any time, so multiple controllers can be queried through one interface at the cost of overwriting the previous state. Check TotalPorts if your program supports more than one controller.

  RightStickXDOUBLERight analog stick value for X axis, between -1.0 and 1.0.
  RightStickYDOUBLERight analog stick value for Y axis, between -1.0 and 1.0.
  RightTriggerDOUBLERight trigger value between 0.0 and 1.0.
  TotalPortsINTReports the total number of controllers connected to the system.

Actions

The following actions are currently supported:

QueryGet the current controller state.