API Reference

Class List

GamePads

Input handler for accessing GamePad input.

Summary

Methods

getAxis

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

isPressed

Returns true if the button on the pad requested is pressed.

poll

Poll for the latest data from the gamepad API.

update

Update the current and previous state of the gamepads.

wasPressed

Returns true if the button was pressed since the last frame.

wasReleased

Returns true if the button was released since the last frame.

Details

Constructor

GamePads()

Methods

getAxis(index, axes)

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

Parameters

indexnumber

The index of the pad to check, use constants PAD_1, PAD_2, etc.

axesnumber

The axes to get the value of, use constants 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

indexnumber

The index of the pad to check, use constants PAD_1, PAD_2, etc.

buttonnumber

The button to test, use constants PAD_FACE_1, etc.

Returns

boolean

True if the button is pressed.

poll([pads])

Poll for the latest data from the gamepad API.

var gamepads = new pc.GamePads();
var pads = gamepads.poll();

Parameters

padsobject[]

An optional array used to receive the gamepads mapping. This array will be returned by this function.

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

indexnumber

The index of the pad to check, use constants PAD_1, PAD_2, etc.

buttonnumber

The button to test, use constants PAD_FACE_1, etc.

Returns

boolean

True if the button was pressed since the last frame.

wasReleased(index, button)

Returns true if the button was released since the last frame.

Parameters

indexnumber

The index of the pad to check, use constants PAD_1, PAD_2, etc.

buttonnumber

The button to test, use constants PAD_FACE_1, etc.

Returns

boolean

True if the button was released since the last frame.