I'm having trouble using the BUTTON_DPAD keys.
In my activity I have the following setup:
public boolean onKeyDown(int keyCode, KeyEvent event) {
boolean handled = OuyaController.onKeyDown(keyCode, event);
return handled || super.onKeyDown(keyCode, event);
}
On the Controller side I want to check if the user pressed the DPADF or one of the analoge sticks:
if(c.getButton(OuyaController.BUTTON_DPAD_DOWN) || fYAchsis > 0.5f)
{
...
}
It seems the event is not handled by the ODK. When I step through the onKeyDown method, the boolean "handled" returns false. All other buttons except the DPAD return true.
Any Idea how I can handle this different?
Thanks,
Markus
Comments
Apparently some groups of buttons on the controller are receiving different treatments during it's execution than others, or behave differently.
Let's say I call "getButton(int ouyaButton)" inside the main game loop, let's name it update()
I have this:
60 fps.
-------------------------------------------------------------------------------------------------------
OuyaController c ; > Not null and properly instantiated and recognized. ;-)
@Override
public void update()
{
super.update();
if( c.getButton(OuyaController.BUTTON_O ) ) System.out.println("PRESSING BUTTON_O");
if( c.getButton(OuyaController.BUTTON_L1 ) ) System.out.println("PRESSING BUTTON_L1");
}
-------------------------------------------------------------------------------------------------------
GREEN = WORKING.
RED = NOT WORKING.
The GREEN GROUP of inputs recognizes the commands passed through "getButton()"method instantly while they are pressed. Very smooth, very fast and constantly.
They are:
O, U, Y, A, L3, R3.
Some inputs are not working softly, and apparently they behave like a keyboard input in a text box . When I press and hold the button, the command executes a single time, a little break happens, and then it continues the execution but not so fast. The RED GROUP, they are:
D-Pad up down left right, L1, L2, R1, R2.
This problem causes the update() method unable to recognize the inputs coming from the Red Group.
I could see that this also happens in the example "Ouya Controller Test", especially if you have more than one controller paired. The Green group goes OK, but not the Red group: notice how the d-pad is flashing, unlike OUYA buttons that simply stay lit when pressed.
One possible solution would be to create your own boolean flags for each of the buttons and set their values inside the method keyDown (keyCode) and keyup (keyCode) like:
public boolean Button_LEFT;
public boolean Button_RIGHT;
public void handleKeyDown (keycode)
{
if (keycode == OuyaControllers.BUTTON_DPAD_LEFT) Button_LEFT = true;
if (keycode == OuyaControllers.BUTTON_DPAD_RIGHT) Button_RIGHT = true;
}
public void handleKeyUP (keycode)
{
if (keycode == OuyaControllers.BUTTON_DPAD_LEFT) Button_LEFT = false;
if (keycode == OuyaControllers.BUTTON_DPAD_RIGHT) Button_RIGHT = false;
}
http://forums.ouya.tv/discussion/comment/5706#Comment_5706
I'd love to use the methods "controller. GetButton ()" inside the updates (), but at the moment I do not know if I'm doing something wrong or if this really could be a good update on the next version of ODK. I just do not understand why the buttons behave differently from each other.
They also could include justPressed(keycode) and justReleased(keycode) methods.