1 decade ago by ansimuz
Hi
I am trying to implement gamepad support to my game and been having some issues detecting up and down events from the gamepad.
The thing is that if i press any button it will be detected as is beign on autofire. I am trying to solve this by checking the timestamp as described in this article: http://www.html5rocks.com/en/tutorials/doodles/gamepad/?redirect_from_locale=es#toc-presses-movement
gamePadShoot: function(state){
this.gamepadUpdate();
if(this.gamepad.buttons[this.gamepad.BUTTONS.FACE_CUADRO]){
if(this.gamepad.timestamp == this.prevGamePadTimeStamp){
// ig.log('same timestamp: button is beign pressedd......');
ig.log('pressed');
return;
}
// save timestamp previous var
this.prevGamePadTimeStamp = this.gamepad.timestamp;
}
}
gamepadUpdate: function(){
this.gamepad = navigator.webkitGetGamepads && navigator.webkitGetGamepads()[2];
// code for buttons
this.gamepad.BUTTONS = {
FACE_EQUIS: 0, // Face (main) buttons
FACE_CIRCULO: 1,
FACE_CUADRO: 2,
FACE_TRIANGULO: 3,
LEFT_SHOULDER: 4, // Top shoulder buttons
RIGHT_SHOULDER: 5,
LEFT_SHOULDER_BOTTOM: 6, // Bottom shoulder buttons
RIGHT_SHOULDER_BOTTOM: 7,
SELECT: 8,
START: 9,
LEFT_ANALOGUE_STICK: 10, // Analogue sticks (if depressible)
RIGHT_ANALOGUE_STICK: 11,
PAD_TOP: 12, // Directional (discrete) pad
PAD_BOTTOM: 13,
PAD_LEFT: 14,
PAD_RIGHT: 15
};
},
Hope you can provide some direction :s
I am trying to implement gamepad support to my game and been having some issues detecting up and down events from the gamepad.
The thing is that if i press any button it will be detected as is beign on autofire. I am trying to solve this by checking the timestamp as described in this article: http://www.html5rocks.com/en/tutorials/doodles/gamepad/?redirect_from_locale=es#toc-presses-movement

Hope you can provide some direction :s