OUYA sample app

Are you intending to develop Corona apps for your OUYA?  Use this app as a starting point.  I put this together myself in a few hours by experimenting; your milage may vary.

996504_10151740386721013_1304459831_n.jp

-- -- main.lua -- display.setStatusBar(display.HiddenStatusBar); local ouya = require("ouya"); local n\_screenWidth = display.contentWidth; local n\_screenHeight = display.contentHeight; local rect\_BehindBackground = display.newRect(-25, -25, n\_screenWidth+50, n\_screenHeight+50); rect\_BehindBackground:setFillColor(0, 0, 255); local rect\_Background = display.newRect(0, 0, n\_screenWidth, n\_screenHeight); rect\_Background:setFillColor(80, 80, 140); local text\_test = display.newText('Testing Ouya Buttons', 0, 0, native.systemFont, 64); text\_test:setTextColor(255, 255, 0); local text\_pxdim = display.newText('Pixel Width: '..display.pixelWidth..' Pixel Height: '..display.pixelHeight, 0, 100, native.systemFont, 64); text\_pxdim:setTextColor(255, 255, 0); local text\_contdim = display.newText('Content Width: '..n\_screenWidth..' Content Height: '..n\_screenHeight, 0, 200, native.systemFont, 64); text\_contdim:setTextColor(255, 255, 0); local text\_origin = display.newText('Origin X: '..display.screenOriginX..' Origin Y: '..display.screenOriginY, 0, 300, native.systemFont, 64); text\_origin:setTextColor(255, 255, 0); controllerListener = function(e) local buttonName = e.buttonName; local isDown = e.isDown; if(isDown) then text\_test.text = buttonName..' -\> press'; else text\_test.text = buttonName..' -\> release'; end end ouya.setListener(controllerListener); -- -- ouya.lua -- local callbackFunction = nil; local isListening = false; local ouyaListener = function(event) local e = {}; if(event.keyName == 'menu') then e.buttonName = 'POWER'; elseif(event.keyName == 'leftShoulderButton1') then e.buttonName = 'L1'; elseif(event.keyName == 'leftShoulderButton2') then e.buttonName = 'L2'; elseif(event.keyName == 'rightShoulderButton1') then e.buttonName = 'R1'; elseif(event.keyName == 'rightShoulderButton2') then e.buttonName = 'R2'; elseif(event.keyName == 'buttonX') then e.buttonName = 'U'; elseif(event.keyName == 'buttonY') then e.buttonName = 'Y'; elseif(event.keyName == 'buttonA') then e.buttonName = 'O'; elseif(event.keyName == 'buttonB') then e.buttonName = 'A'; else e.buttonName = event.keyName; end if (event.phase == "down") then e.isDown = true; elseif (event.phase == "up") then e.isDown = false; end callbackFunction(e); return true end local PUBLIC = {}; PUBLIC.setListener = function(c) if(c ~= nil) then callbackFunction = c; end if(isListening == false) then Runtime:addEventListener("key", ouyaListener); isListening = true; end end PUBLIC.removeListener = function() if(isListening) then Runtime:removeEventListener("key", ouyaListener); isListening = false; end end return PUBLIC; -- -- build.settings -- settings = { orientation = { default = "landscape", supported = { "landscape", } }, android = { mainIntentFilter = { categories = { "tv.ouya.intent.category.GAME" }, }, }, } -- -- config.lua -- application = { content = { width = 720, height = 1280, scale = "letterBox", xAlign = "center", yAlign = "center", imageSuffix = { ["@2x"] = 1.5, }, }, }

Notice that I forced the orientation to ‘landscape’ in build.settings and reversed my width and height in config.lua.  I don’t know why this works, but it was the only way I could get the Ouya to stop cutting off the left and right edges of my screen.

Anyway, if you are wondering what my procedure is for loading/testing, I think I have it pretty well streamlined.

  1. Build for Android like you normally would
  2. Upload to dropbox
  3. On your Ouya, go to Make -> Software -> Browser
  4. When the Browser pops up, enter the URL of the APK you uploaded to dropbox.  At first I found the Ouya browser to be fairly infuriating, but I discovered there is a way to create a bookmark and alter its URL.  That made things so much easier later on.  You may also want to put your dropbox public link to bit.ly to save yourself some typing.
  5. When the Ouya’s browser sees an APK you should see “Starting download…”
  6. Now back out of your browser, all the way back to the start, and go into Manage -> System -> Advanced.
  7. This resembles an actual Android settings page.  Find your way to Storage -> Downloaded.
  8. You should see the APK you just downloaded.  Select it and hit “O”.  It will tell you you are about to install an app.  Say yes.
  9. If your build.settings is correct, your app will show up under Play on the start page.  If it doesn’t, look under Make -> Software.

Happy coding & what not,

GreenCastle

Cool, the cat is crucial for the setup!

Don’t forget to add an Ouya sized app icon.  Just add a file named “Icon-ouya.png” to your Corona project directory that is 732x412 pixels large.  The newest daily build of the Corona Simulator will then automatically inject that app icon into the APK.  We’ve documented this here…

   http://docs.coronalabs.com/daily/guide/distribution/buildSettings/index.html#ouya

Attached is an Ouya sized icon that we plan on adding to our upcoming Ouya sample project.

Big thanks green.castle for your instructions

I have got this working pretty well, only the bindings for the right joystick (up,down,left,right) don’t seem to be working. Is there something I am missing?

Anyone from Corona can give us a time frame for the IAP to be ready?

Currently you cannot receive input from the right joystick.  This is because we don’t support analog axis input yet.  That’ll come later this month.  For the left joystick, notice that you are only receiving digital up/down/left/right key events from it instead of analog axis input too.

A developer at Ouya (the company) is creating an Ouya plugin that will allow you to do in-app purchases and game network functionality.  No ETA yet, but he is actively working on it.

Our newest daily build now provides information about the device that key events come from.  This allows you to identify input coming from different controllers.  Have a look at our updated documentation here…

   http://docs.coronalabs.com/daily/api/event/key/device.html

   http://docs.coronalabs.com/daily/api/type/InputDevice/index.html

There’s more to come!

Excited for the plug-in!! Hope that’s coming soon - the Ouya market is primed and ready!

Happy to hear that!  We’ve been working hard on this for sure.

Oh, and as an added bonus, our newest daily build supports mouse events.  Every Ouya game controller comes with a touchpad which allows you to manipulate the mouse cursor onscreen.  This can come in handy if you want to add mouse hover effects to your app.  Mouse clicks register as tap and touch events, making porting apps easy.  Have a look at our API documentation via the link below for more details…

   http://docs.coronalabs.com/daily/api/event/mouse/index.html

Cool, the cat is crucial for the setup!

Awesome! Any ETA or news on the plug-in yet?

Don’t forget to add an Ouya sized app icon.  Just add a file named “Icon-ouya.png” to your Corona project directory that is 732x412 pixels large.  The newest daily build of the Corona Simulator will then automatically inject that app icon into the APK.  We’ve documented this here…

   http://docs.coronalabs.com/daily/guide/distribution/buildSettings/index.html#ouya

Attached is an Ouya sized icon that we plan on adding to our upcoming Ouya sample project.

Everyone,

Today’s daily build contains another major input device update.

We now have a means of fetching all connected input devices via the following API…
   http://docs.coronalabs.com/daily/api/library/system/getInputDevices.html

We’ve added several new properties/methods to our InputDevice object in Lua. You can now read its current connection status. We’ve renamed properties “permanentStringId” to “permanentId” and “aliasName” to “displayName”. We’ve also added vibration support, but it is untested, and Ouya game controllers do not supports vibration feedback. But if you try hooking up a PS3 controller to your Ouya (or Android device) then feel free to give it a go.
   http://docs.coronalabs.com/daily/api/type/InputDevice/index.html

We’ve also added an “inputDeviceStatus” event which you can used to detect when the status of an input device changes, such as when it connects/disconnects from the system, or when it has been reconfigured. Note that Android unfortunately takes 16 seconds to determine when a bluetooth device has been disconnected, which is unfortunate. I wanted this to be used to pause a game in case the Ouya controller’s batteries suddenly died.
   http://docs.coronalabs.com/daily/api/event/inputDeviceStatus/index.html

In any case, we now have new toys for you to play with.  Have at it!  :)

And now that we think we have a solid input device foundation to build off of, we’ll be working on axis input next! I know many Corona developers have been dying for that feature. Thank you so much for your patience.

Thanks Josh.  Please let us know when support for InputDevices comes to an official release (for those of us Corona fans who can no longer justify maintaining Pro)

@Josh: This is awesome! I am currently adding Ouya support to the alpha-build of my game and I am very excited about the results so far!!! :slight_smile:

green.castle,

The next Corona release will include Ouya and input device support.  We haven’t set a release date yet because we’re taking the time to tweak and tune and make this thing “right” for the upcoming release.  We’re not shy about announcing new releases of Corona.  So, I’m sure you’ll here something.  :)

CineTek,

I’m glad you’re liking it so far.  And if you have any feedback for us, then please feel free to let us know.

So far, I’m still thinking I need to make some tweaks on how to handle connected/disconnected game controllers.  Currently, if you connect a gamepad to an Android device, it will be assigned an InputDevice.descriptor of “Joystick 1”.  If you disconnect that gamepad and then re-connect it (which can happen when the batteries die), our newest daily build now allows it to come back as “Joystick 1”.  This I’m fine with.  However, in the case where the first gamepad is disconnected (or its batteries fail) and the player connects a different gamepad, then Corona will register it as “Joystick 2”.  I’m currently debating if this is the correct behavior or not.  Corona does recognize a totally different gamepad has been connected to the system.  Should Corona assume its a new player joining the game or is it player 1 just swapping controllers?  This is one of those things we want to make sure to get right by the upcoming release.

I’m also thinking that the key event name “unknown” was a bad idea and we should always provide a unique key name such as the hex value of the key code that we don’t recognize.  The reason I’m thinking this is because I’d like to provide mouse button up/down events via Corona’s key events, but mouse buttons do not have key code on Android… but they do on Windows, but Windows does not have key codes for gamepad/joystick buttons.  None of this pertinent to Ouya, but this is just us trying to make this thing as cross-platform as possible before release.

This sounds very interesting and it seems like Corona is moving in the right direction :slight_smile:

But unfortunately I was not able to test the latest features because I can not build for Android anymore :confused: I´ve re-installed some of the older Corona Builds because I thought that this might be a bug of daily build 1170, but it does not work so far.

The sample apps do not work either :confused:

Max

I see in the log that your app is using a “custom build ID”.  This tells Corona to build your app with a particular daily build version instead of the version that you are running.
 
Do you have the following setting in your “build.settings” file?

settings = { build = { custom = "1234567890" } } 

 
If so, then remove it and rebuild your app.  That will tell Corona to build the app using the daily build version that you are currently running with.

No, I do not have this line in my build.settings file. The other apps (sample apps) do not have these lines either.

I take it back.  The custom build ID message is normal for daily build versions.  They’re just not used in release versions.

Does this build error only happen with this one app?  Does it happen with any of our sample apps?

Also, it may have just been a server blip at the time, which should be rare.  I just did a build with 1170 now and it worked fine.

Well, it happens with all apps. But it seems to be a problem with my PC… It worked fine a few months ago, and today I reinstalled java by using an installer called “jdk-7u25-windows-i586.exe” (it comes directly from the oracle website)

Hm… I have installed Java 64 bit as well, I will delete it and see if that helps.

Edit: And android builds work fine on my Macbook…