2013:
Razer Hangout July 15th (1:00:00) |
Examples are included at the base GIT path.
Virtual Controller - Maps Cortex
controllers to multiple virtual controllers
####Corona Enterprise Examples
InAppPurchases - Adds Java/LUA hooks for in-app-purchases in Corona Enterprise
####Corona Pro Examples
InAppPurchasesPlugin - Uses Cortex
plugin for in-app-purchases for Mac and Windows (required Corona PRO)
Corona SDK - http://coronalabs.com/products/corona-sdk/
Corona SDK Daily Builds - http://developer.coronalabs.com/downloads/daily-builds
Corona Enterpise Daily Builds - http://developer.coronalabs.com/downloads/enterprise-daily-builds
Corona Resources - http://coronalabs.com/resources/
Mastering Corona SDK - http://masteringcoronasdk.com/
Corona Editor - http://coronalabs.com/blog/2013/12/11/corona-editor-is-now-1-0/
Lua Spec - http://www.lua.org/manual/5.3/
The Corona Enterprise SDK goes into the subfolder of your Mac's Application folder
Corona Enterprise includes sample applications:
Applications/CoronaEnterprise/Samples/
Initially when setting up Corona Enterprise, the license needs to be authorized via the command-line.
/Applications/CoronaEnterprise/Corona/mac/bin/CoronaBuilder.app/Contents/MacOS/CoronaBuilder authorize your_email your_password
I had to edit the build script to add paths to the ant includes:
Applications/CoronaEnterprise/Corona/android/lib/Corona/build.xml
<property file="${user.dir}/local.properties" /> <property file="${user.dir}/ant.properties" /> <import file="${user.dir}/custom_rules.xml" optional="true" />
###Recommended Tools
Outlaw IDE - http://outlawgametools.com/outlaw-code-editor-and-project-manager/
#Full Document
The ouya-sdk-examples are targeted towards Corona Enterprise users intending to publish to the Cortex
platform.
Building Corona Enterpise examples that use Android java requires the Mac platform. Samples that use the OUYA Plugin for Corona will build on Mac or Windows.
Welcome to the Corona Enterprise development club. These examples provide a quick way to add Cortex
controllers and in-app-purchase support to your game.
The following examples apply to the Corona Simulator version.
Build for Android
with Command+Shift+B which will produce an APK that you can install with adb commands.
adb install -r /path/to/Example.apk
Corona scripts are Lua scripts.
The Corona Simulator doesn't have direct access to the Android.manifest, where build.settings gives you access to modify settings indirectly.
Add the intent filter so that your game appears in the Cortex
Play Category.
settings =
{
android =
{
mainIntentFilter =
{
categories = { "tv.ouya.intent.category.GAME" },
}
},
}
Set the orientation to landscape left.
settings =
{
orientation = {
default = "landscapeLeft",
supported = { "landscapeLeft", },
},
}
Corona is designed to scale up, not down. So you want to specify 720p which will scale up to 1080p.
application =
{
content =
{
width = 1280,
height = 720,
scale = "letterbox",
},
}
The starting point for your Corona game.
Subscribe to OUYA-Everywhere input events.
lua
if nil ~= ouyaSDK and nil ~= ouyaSDK.asyncLuaOuyaInitInput then
ouyaSDK.asyncLuaOuyaInitInput(inputs.onGenericMotionEvent, inputs.onKeyDown, inputs.onKeyUp);
end
Axis events come in with the onGenericMotionEvent callback. playerNum is the controller number 0 through 3. (Zero-based) Axis is the axis number for the event. Val is the floating input value for the axis.
lua
inputs.onGenericMotionEvent = function (playerNum, axis, val)
end
The supported axis
values are below.
OuyaController.AXIS_LS_X
OuyaController.AXIS_LS_Y
OuyaController.AXIS_RS_X
OuyaController.AXIS_RS_Y
OuyaController.AXIS_L2
OuyaController.AXIS_R2
Button events come in with the onKeyDown and onKeyUp events. PlayerNum is the controller number 0 through 3. (Zero-based). Button is the button number for the event.
lua
inputs.onKeyDown = function (playerNum, button)
end
inputs.onKeyUp = function (playerNum, button)
end
The supported button
values are below.
OuyaController.BUTTON_O
OuyaController.BUTTON_U
OuyaController.BUTTON_Y
OuyaController.BUTTON_A
OuyaController.BUTTON_L1
OuyaController.BUTTON_R1
OuyaController.BUTTON_L3
OuyaController.BUTTON_R3
OuyaController.BUTTON_DPAD_UP
OuyaController.BUTTON_DPAD_DOWN
OuyaController.BUTTON_DPAD_RIGHT
OuyaController.BUTTON_DPAD_LEFT
OuyaController.BUTTON_MENU
OuyaController.BUTTON_MENU
can be used to detect the menu button press.
lua
if (button == OuyaController.BUTTON_MENU) then
end
Use OuyaController
buttons to determine which button was pressed in the event.
lua
if (button == OuyaController.BUTTON_DPAD_LEFT) then
end
Open the Corona Simulator at the path - ouya-sdk-examples/Corona/VirtualController/
Main creates the virtual controller sprites.
globals.controllers =
{
ui.createController(1, 150, 500, 2, 2),
ui.createController(2, 150, 1200, 2, 2),
ui.createController(3, 850, 500, 2, 2),
ui.createController(4, 850, 1200, 2, 2)
};
Globals defines the set of global controller objects handles in other scripts.
These are some helper lua scripts for creating and fading sprites.
The axis and button events pass through to the controller sprites to highlight button presses and move the virtual axises.
This script handles creation of the virtual controller sprites and loads the texture sprite objects.
The following examples apply to the Corona Enterprise version.
As with Corona Simulator projects the Corona subfolder can be opened and tested in Corona Simulator to validate the Lua script part of the project.
ouya-sdk-examples/Corona/InAppPurchases/Corona/
The android portion of the project cannot be compiled in the Corona Simulator and is compiled in the terminal or command line.
ouya-sdk-examples/Corona/InAppPurchases/android/
The standard Android configuration that can be customized for Corona. Here you can customize the CoronaApplication, CoronaActivity, and intent filters.
This is a convenience shell script that clears the generated and binary files. The script invokes the build script and installs the build to the connected android device.
This is a convenience shell script that installs the build android package.
Final builds should use a custom keystore. The debug keystore can be used for testing builds.
Local properties defines the Android SDK path and the keystore settings for the build.
sdk.dir=~/android/android-sdk-macosx
key.alias=androiddebugkey
key.store=debug.keystore
key.store.password=android
key.alias.password=android
If you update the Android SDK path and generate local.properties be sure to readd the properties above.
android update project --path .
The Cortex
ODK library used by Corona.
Contained within CoronaRuntimeEventHandler defines Lua fuction interfaces that allow Corona Lua scripts to invoke Java methods.
The activity is used to load the signing key resource and initialize the CoronaOuyaPlugin for in-app-purchases.
This provides the Lua interface to Java to fetch the gamer uuid.
This provides the Lua interface to Java to request the product details.
This provides the Lua interface to Java to request a purchase.
This provides the Lua interface to Java to request receipts.
The callback methods extract the arguments from the Lua calling method and returning the results to Lua after the service is invoked. Each callback implements onSuccess, onFailure, and onCancel methods.
CallbacksRequestGamerInfo.java
CallbacksRequestProducts.java
CallbacksRequestPurchase.java
CallbacksRequestPurchase.java
CallbacksRequestReceipts.java
The Corona Ouya Facade is an interface between the callbacks above and the OuyaFacade which directly interacts with the in-app-purchase service. The "Async" methods pass the LuaState to the "Callbacks" and then invoke the "CoronaOuyaPlugin" which invokes the "OuyaFacade". The "CoronaOuyaFacade" services complete and invoke the "Callbacks" and the results are returned to Lua.
The Corona Ouya Plugin wraps invoking methods on the OuyaFacade. The CoronaOuyaPlugin provides the Java listeners for the OuyaFacade callbacks.
This is an interface that holds static references and accessors for easy access between the SDK classes.
When the CoronaOuyaFacade listener hits the onSuccess, onFailure, or onCancel callback the corresponding Lua callback is called.
Corona/callbacksRequestGamerInfo.lua
Corona/callbacksRequestProducts.lua
Corona/callbacksRequestPurchase.lua
Corona/callbacksRequestReceipts.lua
Store all the Lua script globals in one place.
These are some helper lua scripts for creating buttons and fading sprites.
This lua script provides the input handlers and navigation through the main menu. When the main buttons are clicked this script invokes the Java interfaces and supplies the Lua callbacks for the onSuccess, onFailure, and onCancel callbacks.
Be sure to set your developer id from the developer portal.
local json = require "json"
if nil ~= ouyaSDK and nil ~= ouyaSDK.initOuyaPlugin then
local data = {
[1] = {
["key"] = "tv.ouya.developer_id",
["value"] = "310a8f51-4d6e-4ae5-bda0-b93878e5f5d0"
}};
local jsonData = json.encode(data);
ouyaSDK.initOuyaPlugin(callbacksInitOuyaPlugin.onSuccess, callbacksInitOuyaPlugin.onFailure, jsonData);
end
The main script sets up the basic button and text layout of the application. The key input listener is also registered here.
The UI script handles displaying the products and receipts using the response data from the in-app-purchase service.
initOuyaPlugin
supports additional strings to make the game compatible with OUYA Everywhere devices.
-
tv.ouya.developer_id
- The developer UUID can be found in the developer portal after logging in. -
com.xiaomi.app_id
- The Xiaomi App Id is provided by the content team, emailofficehours@ouya.tv
to obtain your key. -
com.xiaomi.app_key
- The Xiaomi App Key is provided by the content team, emailofficehours@ouya.tv
to obtain your key. -
tv.ouya.product_id_list
- The product id list is a comma separated list of product ids that can be purchased in the game.
local json = require "json"
if nil ~= ouyaSDK and nil ~= ouyaSDK.initOuyaPlugin then
local data = {
[1] = {
["key"] = "tv.ouya.developer_id",
["value"] = "00000000-0000-0000-0000-000000000000"
},
[2] = {
["key"] = "com.xiaomi.app_id",
["value"] = "0000000000000"
},
[3] = {
["key"] = "com.xiaomi.app_key",
["value"] = "000000000000000000"
},
[4] = {
["key"] = "tv.ouya.product_id_list",
["value"] = "long_sword,sharp_axe,cool_level,awesome_sauce"
}};
local jsonData = json.encode(data);
ouyaSDK.initOuyaPlugin(callbacksInitOuyaPlugin.onSuccess, callbacksInitOuyaPlugin.onFailure, jsonData);
end
- The screensaver should be disabled while your game is running. By using the OUYA-Corona plugin, the screensaver will automatically be disabled.
The Corona
documentation has info about how to include Cortex
and Xiaomi
store icons.
-
The
Icon-ouya.png
should be 732x412 and placed into your Corona project fodler. -
The
Icon-ouya-xiaomi.png
should be 284x160 and placed into your Corona project fodler.
In order to use the Cortex
plugin be sure to include the plugin_ouya.lua script in your Corona
project folder.
When a Corona
game starts be sure to check that the Cortex
plugin is available before loading the game. Games that do not check IsAvailable
may flicker or appear to load twice.
local ouya = require("plugin.ouya") -- load the ouya plugin
plugin_ouya = require "plugin_ouya"
if nil ~= plugin_ouya and nil ~= plugin_ouya.luaOuyaIsAvailable then
print ("*** Check if plugin is available **** Is Available??? == " .. tostring(plugin_ouya.luaOuyaIsAvailable()))
if plugin_ouya.luaOuyaIsAvailable() then
-- continue loading game
else
-- OUYA Plugin has not loaded
return;
end
else
-- OUYA Plugin has not loaded
return;
end