Class: GamePadController

Controller#GamePadController(renderer, options:Object)

new GamePadController(renderer, options:Object)

Search and initialize a Gamepad and make event listeners available.
tested with X Box controller
Gamepad Example on codepen:
codepen

Check for an example this video on Youtue
This goes in part with this Codepen Demo
Buttons are on 0, 1, 2, 3, 4 ... n, axis are on 100, 101, 102, 103, ... 10n

 1. button 1
 2. button 2
 3. button 3
 4. button 4
 ...
 n. button n

 100. axis1 x
 101. axis1 y
 102. axis2 x
 103. axis2 y
 ...
 10n. axisn y
 10n. axisn y

Parameters:
Name Type Description
renderer GlRenderer

GlRenderer object

options:Object
Implements:
Author:
  • Sense Studios
Source:
Example
var gamepad1 = new GamePadController( renderer, {});
 gamepad1.init()
 gamepad1.render()

 // do something on button 1, should return [ 1, 1 ] on down and [ 1, 0 ] on keyup
 gamepad1.addEventListener( 1, function( _arr ) { console.log( _arr ) })

 // do something with left-axis-x, should return [ 100, 0.34295876 ]
 gamepad1.addEventListener( 100, function( _arr ) { console.log( _arr ) })

Members

bypass :boolean

Type:
  • boolean
Source:

debug :boolean

Type:
  • boolean
Source:

gamepad_index :integer

when multiple devices identify as gamepads, use ie. gamepad1.gamepad_index = 1 to select the second gamepad [0, 1, 2, ...]

Type:
  • integer
Source:

Methods

addEventListener(_target, _callback)

addEventListener

Parameters:
Name Type Description
_target integer

the number of controller being pressed

_callback function

the callback to be executed

Source:
Example
function doSomething(_arr ) {
   console.log('pressed1', arr)
 }
 gamepad.addEventListener(1, function() )

getNodes()

getNodes -- helper, shows current nodes

Source:

removeEventListener(_target)

removeEventListener

Parameters:
Name Type Description
_target integer

the number of controller being pressed

Source:
Example
gamepad.removeEventListener(1)

(static) connect()

connect, should be automatic, but you can always call gamepad1.connect()

Source:

(inner) init()

init, should be automatic, but you can always call gamepad.init() yourself

Source:

(inner) update()

update, should be automatic, but you can always call gamepad1.update()

Source: