From what I gathered from the Ouya SDK docs, the Ouya SDK has some own methods for Gamepad input. You can't use the HTML5 Gamepad API, otherwise you could just get the
Gamepad plugin that comes with the Jump'n'Run example.
But this plugin gives a good starting point for one that utilizes the Ouya SDK. If I understand the
Ouya SDK docs correctly, you just need to set up some global functions
onKeyUp
,
onKeyDown
(which is weird, but ok) and you're good to go.
Soooo, you'd end up with something like this (totally untested!):
ig.module(
'plugins.ouya-gamepad'
)
.requires(
'impact.input',
'impact.game'
)
.defines(function(){
// Assign some values to the Gamepad buttons. We use an offset of 512
// here so we don't collide with the keyboard buttons when binding.
ig.OUYA_OFFSET = 512;
ig.OUYA = {
AXIS_LS_X: 0+OUYA_OFFSET,
AXIS_LS_Y: 1+OUYA_OFFSET,
AXIS_RS_X: 11+OUYA_OFFSET,
AXIS_RS_Y: 14+OUYA_OFFSET,
AXIS_L2: 17+OUYA_OFFSET,
AXIS_R2: 18+OUYA_OFFSET,
BUTTON_O: 96+OUYA_OFFSET,
BUTTON_U: 99+OUYA_OFFSET,
BUTTON_Y: 100+OUYA_OFFSET,
BUTTON_A: 97+OUYA_OFFSET,
BUTTON_L1: 102+OUYA_OFFSET,
BUTTON_R1: 103+OUYA_OFFSET,
BUTTON_L3: 106+OUYA_OFFSET,
BUTTON_R3: 107+OUYA_OFFSET,
BUTTON_DPAD_UP: 19+OUYA_OFFSET,
BUTTON_DPAD_DOWN: 20+OUYA_OFFSET,
BUTTON_DPAD_RIGHT: 22+OUYA_OFFSET,
BUTTON_DPAD_LEFT: 21+OUYA_OFFSET,
BUTTON_MENU: 82+OUYA_OFFSET,
MAX_CONTROLLERS: 4
};
ig.Input.inject({
ouyaButtonDown: function(button) {
var action = this.bindings[button + ig.OUYA_OFFSET];
if( action ) {
this.actions[action] = true;
if( !this.locks[action] ) {
this.presses[action] = true;
this.locks[action] = true;
}
}
},
ouyaButtonUp: function(button) {
var action = this.bindings[button + ig.OUYA_OFFSET];
if( action ) {
this.delayedKeyup[action] = true;
}
}
});
// Global callbacks for the OUYA SDK
window.onKeyDown = function(playerNum, button) {
if( !ig.input ) { return; } // game hasn't started yet. nothing to do.
ig.input.ouyaButtonDown( button );
};
window.onKeyUp = function(playerNum, button) {
if( !ig.input ) { return; } // game hasn't started yet. nothing to do.
ig.input.ouyaButtonUp( button );
};
});
With this plugin, you should be able to bind gamepad buttons like so:
ig.input.bind(ig.OUYA.BUTTON_O, 'jump');
Note that this plugin totally ignores the controller (i.e. player1 or player2...). Each O-Button on each connected controller will trigger the
'jump'
. If you don&
039;t want that, simply check if #playerNum == 1
in the callbacks and return if it doesn't.