Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by ansimuz

Hey,

I am in the process of putting my game in OUYA which is pretty easy without the need of a wrapper lke cocoonjs. See: https://github.com/ouya/docs/blob/master/html5.md

Now i want to bind the OUYA controller to press events and so. Its there an script or plug in for this.

1 decade ago by dominic

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.

1 decade ago by ansimuz

I did a quick test and its working!

I'll post here if any issue arise.

Thanks Dominic

8 years ago by freeman91

Hi I have a similar issue I am using this plugin to implement gamepad support to my game: https://github.com/ansimuz/BitWars/blob/master/lib/plugins/gamepad.js

It works great on the ouya but the problem is that only player 1 works and I want the game to be controlled by any connected gamepad, is there anything I can edit so that the plugin ignores the controller (i.e. player1 or player2...). So that a button on each connected controller will trigger the 'jump' for example like mentioned posts above.

8 years ago by Fravio4

ok, this part
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;
}
}
},
Page 1 of 1
« first « previous next › last »