API Reference

Class List

pc.GamePads

Input handler for accessing GamePad input

Summary

Methods

getAxisGet the value of one of the analogue axes of the pad
isPressedReturns true if the button on the pad requested is pressed
pollPoll for the latest data from the gamepad API.
updateUpdate the current and previous state of the gamepads.
wasPressedReturns true if the button was pressed since the last frame

Details

Constructor

GamePads()

Methods

getAxis(index, axes)

Get the value of one of the analogue axes of the pad

Parameters

indexNumberThe index of the pad to check, use constants pc.PAD_1, pc.PAD_2, etc
axesNumberThe axes to get the value of, use constants pc.PAD_L_STICK_X, etc

Returns

Number The value of the axis between -1 and 1.

isPressed(index, button)

Returns true if the button on the pad requested is pressed

Parameters

indexNumberThe index of the pad to check, use constants pc.PAD_1, pc.PAD_2, etc
buttonNumberThe button to test, use constants pc.PAD_FACE_1, etc

Returns

Boolean True if the button is pressed

poll()

Poll for the latest data from the gamepad API.

var gamepads = new pc.GamePads();
  var pads = gamepads.poll();
  // pads[0] = { map: , pad:  }

Returns

Object[] An array of gamepads and mappings for the model of gamepad that is attached

update()

Update the current and previous state of the gamepads. This must be called every frame for wasPressed() to work

wasPressed(index, button)

Returns true if the button was pressed since the last frame

Parameters

indexNumberThe index of the pad to check, use constants pc.PAD_1, pc.PAD_2, etc
buttonNumberThe button to test, use constants pc.PAD_FACE_1, etc

Returns

Boolean True if the button was pressed since the last frame