Flixel - Android : Ouya Controller

TomSapoTomSapo Posts: 12Member
edited January 2013 in Native Development
Can someone help make Ouya Controller work inside a project using Flixel Android?

http://code.google.com/p/flixel-android/

Post edited by TomSapo on

Comments

  • agamerguyagamerguy Posts: 9Member
    My time is very limited, but I'm going to attempt to get this working.
  • mjoynermjoyner Posts: 168Member
    It looks libGDX based, any reason to not use the brand new Controllers extension supplied with libGDX?
  • agamerguyagamerguy Posts: 9Member
    Good news is I was able to work a little on this. Thanks mjoyner for the tip. I haven't used libGDX or Flixel before a few days ago, but I'm liking what I'm seeing from both.

    I started using Flixel with the setupui for flixel which included an Oct 2012 release of libGDX. The latest version of libGDX does have Ouya Controller support. Not sure how well it works, but I wrote the following, mimicking Flixel's keyboard input class:

    import org.flixel.FlxG;
    import org.flixel.system.input.Input;

    import com.badlogic.gdx.controllers.mappings.Ouya;

    public class OuyaController extends Input
    {
    public boolean BUTTON_O;
    public boolean BUTTON_U;
    public boolean BUTTON_Y;
    public boolean BUTTON_A;
    public boolean BUTTON_DPAD_UP;
    public boolean BUTTON_DPAD_DOWN;
    public boolean BUTTON_DPAD_RIGHT;
    public boolean BUTTON_DPAD_LEFT;
    public boolean BUTTON_L1;
    public boolean BUTTON_L2;
    public boolean BUTTON_L3;
    public boolean BUTTON_R1;
    public boolean BUTTON_R2;
    public boolean BUTTON_R3;

    public OuyaController()
    {
    super();
    // FACE BUTTONS
    addKey("BUTTON_O", Ouya.BUTTON_O);
    addKey("BUTTON_U", Ouya.BUTTON_U);
    addKey("BUTTON_Y", Ouya.BUTTON_Y);
    addKey("BUTTON_A", Ouya.BUTTON_A);
    // DPAD
    addKey("BUTTON_DPAD_UP", Ouya.BUTTON_DPAD_UP);
    addKey("BUTTON_DPAD_DOWN", Ouya.BUTTON_DPAD_DOWN);
    addKey("BUTTON_DPAD_RIGHT", Ouya.BUTTON_DPAD_RIGHT);
    addKey("BUTTON_DPAD_LEFT", Ouya.BUTTON_DPAD_LEFT);
    //FUNCTION KEYS (F1-F12)
    addKey("BUTTON_L1", Ouya.BUTTON_L1);
    addKey("BUTTON_L2", Ouya.BUTTON_L2);
    addKey("BUTTON_L3", Ouya.BUTTON_L3);
    addKey("BUTTON_R1", Ouya.BUTTON_R1);
    addKey("BUTTON_R2", Ouya.BUTTON_R2);
    addKey("BUTTON_R3", Ouya.BUTTON_R3);
    }
    public void handleKeyDown(int KeyCode)
    {
    KeyState o = _map.get(KeyCode);
    if(o.name.isEmpty())
    return;
    if(o.current > 0)
    o.current = 1;
    else
    o.current = 2;
    try {
    OuyaController.class.getField(o.name).setBoolean(this, true);
    } catch (Exception e) {
    FlxG.log("OuyaController", e.getMessage());
    }
    }
    public void handleKeyUp(int KeyCode)
    {
    KeyState o = _map.get(KeyCode);
    if(o.name.isEmpty())
    return;
    if(o.current > 0)
    o.current = -1;
    else
    o.current = 0;
    try {
    OuyaController.class.getField(o.name).setBoolean(this, false);
    } catch (Exception e) {
    FlxG.log("OuyaController", e.getMessage());
    }
    }
    }


    However I'm not sure if it works, because I've not been able test it on Ouya. I get the following error when attempting to install on the emulator as well:

    java.lang.UnsatisfiedLinkError: couldn't load gdx: findLibrary returned null

    I'm unsure I'll be able to have time to correct this before I have to give the Ouya back that I'm borrowing. If not soon, I'll have to wait until mine comes in march.
  • mjoynermjoyner Posts: 168Member
    Use the latest libGDX project setup and compare to what you have in your existing projects. Sounds like you are missing the armabi bins or something similar.
  • TomSapoTomSapo Posts: 12Member
    edited January 2013
     Hey guys, I appreciate the feedback, this solution is quite elegant. 

    I did some testing and i got good results when the buttons were kept pressed, however "justPressed (key)" and "justReleased (key)" behave strangely.
    "justPressed (key)" keeps returning "true" after a few frames while the button is pressed.
    "justReleased (key)" returns "true" forever.

    I first thought it was because there was a controller for each player, however,  the problem persists even if there is only one controller/player .Besides, There is no conflict between the inputs  from one player to another as long as each one has its own controller instantiated.

    Do not know yet what's going on.
    I'll let you know if I find something.

    Thanks.

    [EDIT]

    I guess I am doing something wrong with the Controllers objects...
    When I try with only 1 controller and  regular FlxG.keys.justPressed ("LEFT") or FlxG.keys.justReleased("RIGHT") it works. Unfortunately I do not see how could more than one controller work together using FlxG.keys stuff, I'll do some more tests.





    Post edited by TomSapo on
  • TomSapoTomSapo Posts: 12Member
    edited January 2013
  • agamerguyagamerguy Posts: 9Member
    Thanks for the updates. I had to give back the dev ouya I was borrowing, so I won't be able to continue developing on the system itself until I get mine in March. I will continue to work on my Flixel project and keep an eye on here for solutions to the controller problems.

    I was hoping to make my game single screen multiplayer, so a solution to using multiple controllers would be nice. Thanks again!
  • TomSapoTomSapo Posts: 12Member
    TomSapo said:
    I did some testing and i got good results when the buttons were kept pressed, however "justPressed (key)" and "justReleased (key)" behave strangely.
    "justPressed (key)" keeps returning "true" after a few frames while the button is pressed.
    "justReleased (key)" returns "true" forever.

    Call the OuyaController.update() somewhere inside the loop and it works :)
Sign In or Register to comment.