Compatible with a java game engine?

Hello everyone, 
I am a student and I am working on creating my first game. The engine that I am using is called J Monkey and is a java based engine. This allows android applications to be created from the code written. However I am unsure how this might effect my desire to release it onto the Ouya console. I would like to believe that it might be generated as an Android application and then transferred over to Ouya, however I do not know if this can be done. 

If anyone can help me by clarifying this issue it would be greatly appreciated.

Thank you for your time and have a nice day 

Best Answer

  • SpoonThumbSpoonThumb Posts: 426Member
    edited January 2013 Answer ✓
    Ah, my team for the Create jam are using Jmonkey. You need to install the android plugin, create a jmonkey project, then convert it to an android project. Getting controller input was a pain, but we managed it in the end:

    In your android activity (called MainActivity or something) put a GlobalInputListener to get input that otherwise gets caught by JMonkey and not propogated down to onKeyDown etc:

    <code>
    public class GlobalInputListener implements View.OnKeyListener {

            public boolean onKey(View v, int keyCode, KeyEvent event) {
               
                boolean handled = false;
               
                if (event.getAction() == KeyEvent.ACTION_DOWN) {
                                handled = OuyaController.onKeyDown(keyCode, event);
                                int controllerId = event.getDeviceId();

                               switch (keyCode) {
                case OuyaController.BUTTON_O:
                    O_Down = true;
                    break;
                case OuyaController.BUTTON_U:
                    U_Down = true;
                    break;
                case OuyaController.BUTTON_Y:
                    Y_Down = true;
                    break;
                case OuyaController.BUTTON_A:
                    A_Down = true;
                    break;
                case OuyaController.BUTTON_L1:
                    L1_Down = true;
                    break;
                case OuyaController.BUTTON_R1:
                    R1_Down = true;
                    break;
                case OuyaController.BUTTON_L2:
                    L2_Down = true;
                    break;
                case OuyaController.BUTTON_R2:
                    R2_Down = true;
                    break;
                default:
                    // nothing happening here
                    break;
            }
                }
                                                           
                } else if (event.getAction() == KeyEvent.ACTION_UP) {
                              
                }
               
                return handled;
            }
        }
        GlobalInputListener gil = new GlobalInputListener();

    </code>

    Then use onGenericMotionEvent() to get stick input

    <code>
        @Override
        public boolean onGenericMotionEvent(MotionEvent event) {
            int controllerId = event.getDeviceId();
            boolean handled = OuyaController.onGenericMotionEvent(event);

    OuyaController ouyacontroller = OuyaController.getControllerByDeviceId(deviceId);
            if (ouyacontroller != null) {
                float left_stick_x = ouyacontroller.getAxisValue(OuyaController.AXIS_LS_X);
            }

            return handled || super.onGenericMotionEvent(event);
        }


    </code>

    Edit: As others have mentioned, you still have to do the usual stuff to get a regular android project to work with Ouya (import jar files and add line to manifest iirc)
    Post edited by SpoonThumb on

Answers

  • mjoynermjoyner Posts: 168Member
    If the environment can create standard Android applications, you should be able to shove them into an OUYA without any difficulty.

    Guessing that you can import jars, you should be able to import the OUYA SDK and get access to the gamepad data etc.

    Though it is Eclipse based, you might also want to peruse the blog and forums at the libgdx project: http://libgdx.badlogicgames.com/

    They are putting in specific OUYA stuff, but, only as optional.
  • pendranpendran Posts: 9Member
    Would be great if you could post any experience you made with this setup, as I also wanted to use JMonkey for this purpose, once I had enough time again :)
  • SueseSuese Posts: 120Member
    As far as I can tell J Monkey is for desktops ONLY. 

    Nowhere on their web site do they mention Android compatibility. 

    Let me break down the options I've come across so far..

    ADOBE AIR:

    I'm having a lot of success using the following tool chain:
       FlashDevelop (IDE),  
       Adobe AIR 3.5 (Runtime Environment)
       ActionScript 3 (Programming Language)
       Starling (2D Graphics Framework)
       Away3D (3D Graphics Framework)

    Starling and Away3D have excellent and very straight forward examples and tutorials.
    You will also get excellent performance out of these frameworks.

    Starling's killer-app is Angry Birds.  A very successful game that has deployed well on many platforms including Android and the iPhone.


    ANDROID SDK:

    I ran into lots of dead-ends with the official Android SDK.  The documentation is long-winded, filled with terrible examples, and very incomplete information.

    With the Android SDK I had a lot of difficulty getting a tool-chain the provided performance and easy-of-use.  

    I found the official Android SDK for Java to be lacking in useful documentation and obscured by CrypticCamelCaseIdentifiersWithNoDocumentation.  Most of the 'game frameworks' for Android are a complete joke, their 'killer-app' examples being terribly amateur games nobody has heard of.   Knowing  what techniques to use to handle timing events and screen updates is complete guess-work that will have you combing reference documents for hours.

    (p.s. a 'killer app' is slang for a 'most well-known example')



    UNITY:

    I've heard good things about Unity.  It's more than a programming environment though.  I believe it's a 3D modeller,  level designer, and programming tool all-in-one.   It's great for amateurs and hard-core programmers alike..  or so I'm told.

    If you aren't a complete control freak like me,  you may find Unity to be your best bet.  It really takes care of just about everything and deploys quite nicely on OUYA almost 100% out-of-the-box.

    Unity and OUYA are partners,  so it is officially supported by Team OUYA and Team Unity.
    TheSuese.com - Elite Developer Backer
  • Philip_SmythPhilip_Smyth Posts: 2Member
    edited January 2013
    Thanks guys, i have to say I am surprised I got such a quick response haha. I will let you know how it goes :)
     
    Post edited by Philip_Smyth on
  • pendranpendran Posts: 9Member
    Suese said:
    As far as I can tell J Monkey is for desktops ONLY. 

    Nowhere on their web site do they mention Android compatibility. 
    I found this link about Android Support, which says it's work in progress.
    About Unity... I am not quite sure, but I think that the version you need for developing on the android platform is not for free.
  • Killa_MaakiKilla_Maaki Posts: 504Member
    edited January 2013
    Suese said:
    UNITY:

    I've heard good things about Unity.  It's more than a programming environment though.  I believe it's a 3D modeller,  level designer, and programming tool all-in-one.   It's great for amateurs and hard-core programmers alike..  or so I'm told.

    If you aren't a complete control freak like me,  you may find Unity to be your best bet.  It really takes care of just about everything and deploys quite nicely on OUYA almost 100% out-of-the-box.

    Unity and OUYA are partners,  so it is officially supported by Team OUYA and Team Unity.
    Well, most of that was pretty much dead-on except for the 3D modeller part. It doesn't do 3D modelling ;)
    Well, there are plugins people have developed and released on the Asset Store, such as Gamedraw and ProBuilder, that try to handle 3D modelling (I won ProBuilder in a contest, and I must say it feels a lot like blocking things out in Hammer, and then adding mesh props and decals and other stuff... it's pretty nice).
    Let me just say that while the free version can be a bit off-putting in terms of what it doesn't support, the pro version is totally worth it.
    You get some pretty badass graphics and animation technology with Pro, such as Light Probes (essentially you can fake environment shadows (or even global illumination) on characters with almost no impact on the GPU, and you can even inject your own values into these calculations for stuff like muzzle flashes and explosions)
    Unity Pro has builtin occlusion culling, pathfinding (using Recast, the same engine integrated with Unreal Engine 3), and Unity 4 also introduced Mechanim for character animation (whereas previously we had a pretty standard animation system, now Mechanim gives you blend trees and state machines for your animations, and also lets you pretty easily retarget your animations for humanoid characters, a lot like Unreal)
    I would highly recommend Unity.
    My advice would be to start developing your game now, on Unity Free (as I am doing) and then later either pay for Pro ($3,000 total for Pro and Android Pro), or possibly even start a kickstarter campaign and pay for it that way.
    It's a lot more expensive, but it also looks to offer many more features than JMonkey does.
    To throw out some example games, the games Shadowgun, Shadowgun: DeadZone, and Dead Trigger were all built on the Unity engine.
    Post edited by Killa_Maaki on
    You didn't remember the plot of the Doctor Who movie because there was none; Just a bunch of plot holes strung together.
  • Killa_MaakiKilla_Maaki Posts: 504Member
    edited January 2013
    EDIT: DOUBLE POST REMOVED
    Post edited by Killa_Maaki on
    You didn't remember the plot of the Doctor Who movie because there was none; Just a bunch of plot holes strung together.
  • Killa_MaakiKilla_Maaki Posts: 504Member
    Ooops :C
    Sorry for the double post...
    You didn't remember the plot of the Doctor Who movie because there was none; Just a bunch of plot holes strung together.
  • arcticdogarcticdog Posts: 235Member
    I think MonoGame also deserves a mention here.


    Not Java, but it's C# (which is very similar syntactically.  Unity also uses C# as it's programming language).
      
    MonoGame is based on the XNA game development framework for X-Box 360/Windows.  So as a result of the XNA roots, there is quite a bit of supporting documentation, tutorials and samples out there.  
  • RenanseRenanse Posts: 4Member
    edited January 2013
    Late response, but fwiw I'm currently using Ardor3D's android wrapper to do an Ouya game.

    www.ardor3d.com

    Ardor3D began life almost 5 years ago as a fork from jMonkeyEngine.
    Post edited by Renanse on
  • SpoonThumbSpoonThumb Posts: 426Member
    Someone asked me how to actually communicate between the main JME classes and the AndroidMainActivity class, which has all the OUYA API calls in it. So here is an example:


    /**
     * First create an object in one of the Source Packages to hold data shared across the app
     * In this case, I've created a controller class to record key presses
     */
    public class Controller {

        /**
         * Take out the lock on this object. No input can be received until this lock is released
         */
        public static final AtomicInteger lock = new AtomicInteger();
       
        private int deviceId = -1;

        /**
         * Was O button pressed down
         */
        private boolean O_Down = false;

        /**
         * Left Stick position on X axis
         */
        private float LS_X = 0;

        /**
         * Left Stick position on Y axis
         */
        private float LS_Y = 0;

        /**
         * Right Stick position on X axis
         */
        private float RS_X = 0;

        /**
         * Right Stick position on Y axis
         */
        private float RS_Y = 0;

        public void addKeyDownEvent(int keyCode) {

            synchronized(lock){
               
            switch (keyCode) {
                case OuyaController.BUTTON_O:
                    O_Down = true;
                    break;
                // .... etc
            }
            }
        }

        /**
         * Records the positions of the left and right sticks when a
         * {@link MainActivity#onGenericMotionEvent(android.view.MotionEvent)}
         * is triggered <p> Note: Calls static methods of {@link OuyaController}
         */
        public void updateSticks() {           
                   
                sticksCentred = true;
               
                    OuyaController ouyacontroller = OuyaController.getControllerByDeviceId(deviceId);
            if (ouyacontroller != null) {
                LS_X = ouyacontroller.getAxisValue(OuyaController.AXIS_LS_X);
                LS_Y = ouyacontroller.getAxisValue(OuyaController.AXIS_LS_Y);
                RS_X = ouyacontroller.getAxisValue(OuyaController.AXIS_RS_X);
                RS_Y = ouyacontroller.getAxisValue(OuyaController.AXIS_RS_Y);
            } else {
                        return;
                    }

            if (!isStickNotCentred(LS_X, LS_Y)) { // see ODK samples for where to get this method
                LS_X = 0;
                LS_Y = 0;                       
            } else {
                        sticksCentred = false;
                    }

            if (!isStickNotCentred(RS_X, RS_Y)) {
                RS_X = 0;
                RS_Y = 0;                       
            } else {
                        sticksCentred = false;
                    }
                   
        }

    }

    Obviously, you can call the static OuyaController methods from anywhere, but you won't know when to call them. Rather than simply polling them every time the game loops, you can wait until they are pressed/moved, as per the code in my earlier post: http://forums.ouya.tv/discussion/comment/3528/#Comment_3528

    However, you need some way that both the Main class and the AndroidMainActivity class are using the same instance of Controller (or whatever object you use):

    public class Main extends SimpleApplication {

        /**
         * Note: Player is just a simple object I just made up to represent a player
         */
        ArrayList<Player> players = new ArrayList<Player>();

        /**
         * Adds a player to the game to be associated with the specified controller
         *
         * @param controller the controller used by the player
         * @return true if the player object is successfully added to the game
         */
        public boolean addPlayer(Controller controller) {
            synchronized (players) {
                if (init) {
                    Player nPlayer = new Player(controller, "Models/test_box/test_box.j3o");
                    players.add(nPlayer);
                    return true;
                }
            }
            return false;
        }

    }

    Then in AndroidMainActivity

    public class MainActivity extends AndroidHarness {

        /**
         * Sparse array is a special type of hashmap that comes with android
         * Each Controller object in the array is mapped against a unique int
         * In this case, we use the deviceId as the int
         */
        SparseArray<Controller> controllers = new SparseArray<Controller>();

        @Override
        public boolean onGenericMotionEvent(MotionEvent event) {
            int controllerId = event.getDeviceId();
            boolean handled = OuyaController.onGenericMotionEvent(event);

            Controller controller = getController(controllerId);
            controller.updateSticks();

            return handled || super.onGenericMotionEvent(event);
        }

        /**
         * Gets the controller object for the device or creates a new controller
         * object if one does not already exist (and maps it)
         *
         * @param deviceId the id of the device associated with the controller
         * @return the controller object associated with the deviceId or null if
         * deviceId is invalid
         */
        private Controller getController(int deviceId) {
            Controller controller = controllers.get(deviceId);
            if (controller == null) {
                if (deviceId < 0) {
                    // no device id? Should probably throw an error here
                    return null;
                }
                controller = new Controller(deviceId);

                // This next line is the important line, where we get the Main activity as an object in our
                // AndroidMainActivity, and can pass the controller object across
                // Now there is a shared object, the two classes can communicate between each other

                if (((Main) this.getJmeApplication()).addPlayer(controller)) {

                    // only add the mapping if the player using the controller is successfully created
                    controllers.put(deviceId, controller);
                }
            }
            return controller;
        }

    }
  • DisastormDisastorm Posts: 2Member
    Another alternative 3d java library for android is jpct-ae: http://www.jpct.net/
Sign In or Register to comment.