Construct 2 Engine

Downloads

Open source, clone https://github.com/ouya/ouya-sdk-examples/tree/master/Construct2

Forums

@OUYA - (Construct 2 on OUYA Forums) - http://forums.ouya.tv/categories/construct2-on-ouya

@Construct 2 - (Forums) - https://www.scirra.com/forum/

Getting Started

Intro to Construct 2 (19:40)
Intro to Construct 2 on OUYA

Resources

Construct 2 - https://www.scirra.com/construct2

Supported Platforms - https://www.scirra.com/manual/168/supported-platforms

Construct 2

Construct 2 is an visually programable engine that publishes HTML5.

Setup

Windows

1) Install Construct 2.

2) Install your license file into the C:\Program Files\Construct 2\ folder.

3) Install the Construct 2 exporter changes into your Construct 2 exporters folder.

4) Restart Construct 2

Publishing

Publishing to the OUYA requires that you package the generated HTML5 from Construct 2 into an Android wrapper, Cordova. The wrapper provides accelerated WebGL and accelerated video decoding.

1) Use the menu File->Export project... item.

file export

2) Select HTML5 website and click Next button.

export type

3) Specify the HTML5 output folder and click Next button (this should be the Cordova www folder).

export destination

4) Select Normal style and click the Export button.

export style

5) Return to Construct 2 or open the destination www folder.

destination folder

6) Before the Cordova scripting can be run, be sure to install the Cordova Command-Line Interface.

7) Run the package.cmd script in the root of the project which runs cordova run android.

package command

8) The script builds the Android app, installs, and runs on the connected Android device.

package command

Setup

Before you can use the OuyaSDK be sure to create a game in the developer portal and download the signing key.

The IAP example places the signing key in Construct2\InAppPurchases\platforms\android\assets\key.der which gets packaged when running ouya-sdk-examples\Construct2\InAppPurchases\package.cmd after exporting HTML5 to Construct2\InAppPurchases\www.

Testing

You won't be charged when making IAP purchases of your own game. Be sure to log into the OUYA with the same developer account that the game is created for in the developer portal. You can reverse purchases in the purchase page of the developer portal to test refund scenarios or testing first-time purchases. Look for the View and remove your purchases of your products link on the bottom of the purchase page to refund purchases of your own game.

OuyaSDK API

To access the OUYA SDK, insert an OuyaSDK object into your layout. The OuyaSDK object has to be in the layout for the OuyaSDK events to fire.

Right click the Layout and select Insert New Object.

Insert Object

Select OuyaSDK and click Insert.

Insert

Initialize the OUYA Plugin

Interacting with the OUYA SDK can be done via the event sheet.

Start of Layout

Add an event System\On start of layout.

start of layout

Add actions addInitOuyaPluginValues and initOuyaPlugin to the On start of layout event.

init actions

Developer UUID

The Developer UUID is available in the developer portal. You must be logged in to see your Developer UUID.

init actions

addInitOuyaPluginValues

addInitOuyaPluginValues has key and value arguments. Add a key of "tv.ouya.developer_id". Add a value using your Developer UUID.

init actions

The initOuyaPlugin action will invoke initializing the OUYA Plugin given the values added with addInitOuyaPluginValues.

Add Init Values

Init Events

Initialize OUYA Plugin on Success will be invoked if the OUYA Plugin was initialized.

Initialize OUYA Plugin on Failure will be invoked if the OUYA Plugin failed to initialize.

  • After the success callback, the other IAP actions can be invoked.

  • After the failure callback, be sure to reinvoke the InitOuyaPlugin action to ensure the OUYA plugin successfully initializes.

Init Plugin

Actions can be added to the init events.

Add Event

The onFailure event provides error code and error message fields.

  • OuyaSDK.errorCodeOnFailureInitOuyaPlugin - The failure error code as a number

  • OuyaSDK.errorMessageOnFailureInitOuyaPlugin - The failure error message as a string

Xiaomi Initialization

Back to general info

addInitOuyaPluginValues 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, email officehours@ouya.tv to obtain your key.

  • com.xiaomi.app_key - The Xiaomi App Key is provided by the content team, email officehours@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.

image alt text

Request Gamer Info

The gamer info includes the gamer's username and unique identifier. Add an OuyaSDK\Request Gamer Info action.

Gamer Info

Request Gamer Info has 3 events for on Success, on Failure, and on Cancel.

Request Gamer Info

The Gamer Info fields are available in the onSuccess event.

OuyaSDK.GamerInfoUsername returns the string for the gamer's username which can be used to display in a Text object.

OuyaSDK.GamerInfoUuid returns the string for the gamer's unique identifier.

GamerInfo Uuid

The onFailure event provides error code and error message fields.

  • OuyaSDK.errorCodeOnFailureRequestGamerInfo - The failure error code as a number

  • OuyaSDK.errorMessageOnFailureRequestGamerInfo - The failure error message as a string

Request Products

Requesting products gets the details about the Product created in the developer portal.

{
    "currencyCode": "USD",
    "originalPrice": 2.99,
    "localPrice": 2.99,
    "description": "",
    "name": "Sharp Axe",
    "developerName": "Sample Developer",
    "identifier": "sharp_axe",
    "percentOff": 0
}

Add the action OuyaSDK\Request Products.

Request Products

Request Products takes a string which is a comma separated list of product ids. You can pass a comma separated list "a,b,c,d,e,f" or a single product "my_awesome_sauce".

CSV List

The IAP example waits for a button press before invoking the Request Products action. Button

Request Products has 3 events for on Success, on Failure, and on Cancel.

Request Products

Request Products on Success gets a list of product details. OuyaSDK.ProductsLength returns the count of products returned.

Insert Object

Retrieving product details uses an index from 0 to (OuyaSDK.ProductsLength - 1). Create a global ProductIndex used to get the product details.

Insert Object

Use the Set action to set the ProductIndex to start at the beginning of the products list.

Insert Object

Add a Repeat event to iterate over each of the returned products.

Insert Object

The count will be OuyaSDK.ProductsLength times.

Insert Object

All the OuyaSDK.GetProducts* accessors take the ProductIndex to return the Product item's details.

OuyaSDK.GetProductsIdentifier(ProductIndex) - Returns a string of the product identifier

OuyaSDK.GetProductsName(ProductIndex) - Returns a string of the product name

OuyaSDK.GetProductsDescription(ProductIndex) - Returns a string of the product description

OuyaSDK.GetProductsLocalPrice(ProductIndex) returns a float for the local price of the product.

Increment the ProductIndex with a Set action after looking up the data for each product.

Insert Object

The onFailure event provides error code and error message fields.

  • OuyaSDK.errorCodeOnFailureRequestProducts - The failure error code as a number

  • OuyaSDK.errorMessageOnFailureRequestProducts - The failure error message as a string

Request Purchase

Requesting a purchase requires the Product entitlement or consumable was created in the developer portal.

Add the action OuyaSDK\Request Purchase.

Insert Object

Request Purchase has 3 events for on Success, on Failure, and on Cancel.

Insert Object

The onFailure event provides error code and error message fields.

  • OuyaSDK.errorCodeOnFailureRequestPurchase - The failure error code as a number

  • OuyaSDK.errorMessageOnFailureRequestPurchase - The failure error message as a string

Request Receipts

A receipt indicates that the gamer has purchased your entitlement. After querying the receipts list, iterate through the items to check if your entitlement product_id is found to unlock the full game or feature.


{
    "gamer": "2927b3d9-e940-077a-8f68-af923f52f5d9",
    "uuid": "be05dfcdc4eb0d50",
    "generatedDate": "Thu Jan 01 00:00:00 GMT 1970",
    "localPrice": 0.99,
    "identifier": "cool_level",
    "currency": "USD",
    "purchaseDate": "Tue Nov 11 01:36:12 GMT 2014"
}

Add the action OuyaSDK\Request Receipts.

Insert Object

Request Receipts has 3 events for on Success, on Failure, and on Cancel.

Insert Object

Request Receipts on Success gets a list of receipt details. OuyaSDK.ReceiptsLength returns the count of receipts returned.

Insert Object

Retrieving receipts details uses an index from 0 to (OuyaSDK.ReceiptsLength - 1). Create a global ReceiptIndex used to get the receipt details.

Insert Object

Use the Set action to set the ReceiptIndex to start at the beginning of the receipts list.

Insert Object

Add a Repeat event to iterate over each of the returned receipts.

Insert Object

The count will be OuyaSDK.ReceiptsLength times.

Insert Object

All the OuyaSDK.GetReceipts* accessors take the ReceiptIndex to return the Receipt item's details.

OuyaSDK.GetReceiptsIdentifier(ReceiptIndex) - Returns a string of the product identifier

OuyaSDK.GetReceiptsGeneratedDate(ReceiptIndex) - Returns a string of the generated date

OuyaSDK.GetReceiptsLocalPrice(ReceiptIndex) returns a float for the local price of the receipt.

Increment the ReceiptIndex with a Set action after looking up the data for each product.

Insert Object

The onFailure event provides error code and error message fields.

  • OuyaSDK.errorCodeOnFailureRequestReceipts - The failure error code as a number

  • OuyaSDK.errorMessageOnFailureRequestReceipts - The failure error message as a string

Set Safe Area

Add the action OuyaSDK\Set Safe Area.

Insert Object

The IAP example uses a floating-point SafeAreaAmount global variable that adjusts the safe area amount.

Insert Object

The Set Safe Area action takes a SafeAreaAmount floating-point number. Safe area amounts range from 0.0 with full border to 1.0 with border.

Insert Object

Set Safe Area has 2 events for on Success, and on Failure.

Insert Object

The onFailure event provides error code and error message fields.

  • OuyaSDK.errorCodeOnFailureSetSafeArea - The failure error code as a number

  • OuyaSDK.errorMessageOnFailureSetSafeArea - The failure error message as a string

Shutdown

Add the action OuyaSDK\Shutdown.

Insert Object

Shutdown has 2 events for on Success, and on Failure.

Insert Object

The onFailure event provides error code and error message fields.

  • OuyaSDK.errorCodeOnFailureShutdown - The failure error code as a number

  • OuyaSDK.errorMessageOnFailureShutdown - The failure error message as a string

Examples

The examples are capx files which are complete projects that depend on installing the OuyaSDK Construct 2 plugin.

Virtual Controller

The Virtual Controller example shows 4 images of the OUYA Controller which moves axises and highlights buttons when the physical controller is manipulated. The Virtual Controller example includes support for OUYA-Everywhere.

Virtual Controller Example

Building HTML5 with Construct 2

Open the VirtualController.capx from the Construct2\VirtualController example folder.

Virtual Controller Wrapped In Cordova

1) The initial Cordova project was created with the command-line from the Construct2 folder.

cordova create VirtualController tv.ouya.examples.construct2.virtualcontroller VirtualController

2) Android support is added to the Cordova project with the following command-line from the Construct2/VirtualController folder.

cordova platform add android

3) Use the Cordova command-line to add the cordova-plugin-ouya-sdk plugin.

cordova plugin add https://github.com/ouya/cordova-plugin-ouya-sdk.git#master

4) To build and run the Virtual Controller Example run the following command from the Construct2/VirtualController folder.

cordova run android

5) Manually copy plugins\cordova-plugin-ouya-sdk\src\android\MainActivity.java to platforms\android\src\tv\ouya\examples\construct2\virtualcontroller\MainActivity.java and edit the package name to be tv.ouya.examples.construct2.virtualcontroller. Cordova auto-configs cannot replace XML nodes making this manual one-off necessary.

package tv.ouya.examples.construct2.virtualcontroller;

6) When building in Construct 2 and exporting to HTML5 be sure to output to the Construct2\VirtualController\www folder so that the above command will pick up the files.

In-App-Purchases

The In-App-Purchases example shows making purchases, checking receipts, adjusting the safe area, and exiting the app.

IAP Example

Building HTML5 with Construct 2

Open the InAppPurchases.capx from the Construct2\InAppPurchases example folder.

In-App-Purchases Wrapped In Cordova

1) The initial Cordova project was created with the command-line from the Construct2 folder.

cordova create InAppPurchases tv.ouya.examples.construct2.inapppurchases InAppPurchases

2) Android support is added to the Cordova project with the following command-line from the Construct2/InAppPurchases folder.

cordova platform add android

3) Use the Cordova command-line to add the cordova-plugin-ouya-sdk plugin.

cordova plugin add https://github.com/ouya/cordova-plugin-ouya-sdk.git#master

4) To build and run the In-App-Purchases Example run the following command from the Construct2/InAppPurchases folder.

cordova run android

5) Manually copy plugins\cordova-plugin-ouya-sdk\src\android\MainActivity.java to platforms\android\src\tv\ouya\examples\construct2\inapppurchases\MainActivity.java and edit the package name to be tv.ouya.examples.construct2.inapppurchases. Cordova auto-configs cannot replace XML nodes making this manual one-off necessary.

package tv.ouya.examples.construct2.inapppurchases;

6) When building in Construct 2 and exporting to HTML5 be sure to output to the Construct2\InAppPurchases\www folder so that the above command will pick up the files.