Intro to Construct 2 (19:40) |
Construct 2 - https://www.scirra.com/construct2
Supported Platforms - https://www.scirra.com/manual/168/supported-platforms
Construct 2 is an visually programable engine that publishes HTML5.
-
Install Construct 2.
-
Install your license file into the
C:\Program Files\Construct 2\
folder. -
Install the
Construct 2
exporter changes into yourConstruct 2
exporters folder. -
Restart Construct 2
Publishing to Cortex
requires that you package the generated HTML5
from Construct 2
into an Android wrapper, Cordova
. The wrapper provides accelerated WebGL
and accelerated video decoding.
- Use the menu
File->Export project...
item.
- Select
HTML5 website
and clickNext
button.
- Specify the
HTML5
output folder and clickNext
button (this should be theCordova
www folder).
- Select
Normal style
and click theExport
button.
- Return to
Construct 2
or open the destinationwww
folder.
-
Before the
Cordova
scripting can be run, be sure to install theCordova
Command-Line Interface. -
Run the
package.cmd
script in the root of the project which runscordova run android
.
- The script builds the
Android
app, installs, and runs on the connectedAndroid
device.
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
.
You won't be charged when making IAP purchases of your own game.
Be sure to log into Cortex
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.
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
.
Select OuyaSDK
and click Insert
.
Interacting with the Cortex
SDK can be done via the event sheet
.
Add an event System\On start of layout
.
Add actions addInitOuyaPluginValues
and initOuyaPlugin
to the On start of layout
event.
The Developer UUID
is available in the developer portal.
You must be logged in to see your Developer UUID
.
addInitOuyaPluginValues
has key
and value
arguments.
Add a key
of "tv.ouya.developer_id".
Add a value
using your Developer UUID
.
The initOuyaPlugin
action will invoke initializing the OUYA Plugin given the values added with addInitOuyaPluginValues
.
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 theOUYA
plugin successfully initializes.
Actions can be added to the init events.
The onFailure
event provides error code and error message fields.
-
OuyaSDK.errorCodeOnFailureInitOuyaPlugin
- The failureerror code
as a number -
OuyaSDK.errorMessageOnFailureInitOuyaPlugin
- The failureerror message
as a string
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[email protected]
to obtain your key. -
com.xiaomi.app_key
- The Xiaomi App Key is provided by the content team, email[email protected]
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.
The gamer info includes the gamer's username and unique identifier. Add an OuyaSDK\Request Gamer Info
action.
Request Gamer Info
has 3 events for on Success
, on Failure
, and on Cancel
.
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.
The onFailure
event provides error code and error message fields.
-
OuyaSDK.errorCodeOnFailureRequestGamerInfo
- The failureerror code
as a number -
OuyaSDK.errorMessageOnFailureRequestGamerInfo
- The failureerror message
as a string
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
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"
.
The IAP example waits for a button press before invoking the Request Products
action.
Request Products
has 3 events for on Success
, on Failure
, and on Cancel
.
Request Products on Success
gets a list of product details.
OuyaSDK.ProductsLength
returns the count of products returned.
Retrieving product details uses an index from 0 to (OuyaSDK.ProductsLength
- 1).
Create a global ProductIndex
used to get the product details.
Use the Set
action to set the ProductIndex
to start at the beginning of the products list.
Add a Repeat
event to iterate over each of the returned products.
The count will be OuyaSDK.ProductsLength
times.
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.
The onFailure
event provides error code and error message fields.
-
OuyaSDK.errorCodeOnFailureRequestProducts
- The failureerror code
as a number -
OuyaSDK.errorMessageOnFailureRequestProducts
- The failureerror message
as a string
Requesting a purchase requires the Product entitlement or consumable was created in the developer portal.
Add the action OuyaSDK\Request Purchase
.
Request Purchase
has 3 events for on Success
, on Failure
, and on Cancel
.
The onFailure
event provides error code and error message fields.
-
OuyaSDK.errorCodeOnFailureRequestPurchase
- The failureerror code
as a number -
OuyaSDK.errorMessageOnFailureRequestPurchase
- The failureerror message
as a string
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
.
Request Receipts
has 3 events for on Success
, on Failure
, and on Cancel
.
Request Receipts
on Success gets a list of receipt details. OuyaSDK.ReceiptsLength
returns the count of receipts returned.
Retrieving receipts details uses an index from 0 to (OuyaSDK.ReceiptsLength
- 1). Create a global ReceiptIndex used to get the receipt details.
Use the Set
action to set the ReceiptIndex to start at the beginning of the receipts list.
Add a Repeat
event to iterate over each of the returned receipts.
The count will be OuyaSDK.ReceiptsLength
times.
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.
The onFailure
event provides error code and error message fields.
-
OuyaSDK.errorCodeOnFailureRequestReceipts
- The failureerror code
as a number -
OuyaSDK.errorMessageOnFailureRequestReceipts
- The failureerror message
as a string
Add the action OuyaSDK\Set Safe Area
.
The IAP example uses a floating-point SafeAreaAmount
global variable that adjusts the safe area amount.
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.
Set Safe Area
has 2 events for on Success
, and on Failure
.
The onFailure
event provides error code and error message fields.
-
OuyaSDK.errorCodeOnFailureSetSafeArea
- The failureerror code
as a number -
OuyaSDK.errorMessageOnFailureSetSafeArea
- The failureerror message
as a string
Add the action OuyaSDK\Shutdown
.
Shutdown
has 2 events for on Success
, and on Failure
.
The onFailure
event provides error code and error message fields.
-
OuyaSDK.errorCodeOnFailureShutdown
- The failureerror code
as a number -
OuyaSDK.errorMessageOnFailureShutdown
- The failureerror message
as a string
The examples are capx
files which are complete projects that depend on installing the OuyaSDK
Construct 2 plugin.
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.
Open the VirtualController.capx
from the Construct2\VirtualController
example folder.
- The initial
Cordova
project was created with the command-line from theConstruct2
folder.
cordova create VirtualController tv.ouya.examples.construct2.virtualcontroller VirtualController
Android
support is added to theCordova
project with the following command-line from theConstruct2/VirtualController
folder.
cordova platform add android
- Use the
Cordova
command-line to add thecordova-plugin-ouya-sdk
plugin.
cordova plugin add https://github.com/ouya/cordova-plugin-ouya-sdk.git#master
- To build and run the
Virtual Controller Example
run the following command from theConstruct2/VirtualController
folder.
cordova run android
- Manually copy
plugins\cordova-plugin-ouya-sdk\src\android\MainActivity.java
toplatforms\android\src\tv\ouya\examples\construct2\virtualcontroller\MainActivity.java
and edit the package name to betv.ouya.examples.construct2.virtualcontroller
.Cordova
auto-configs cannot replaceXML
nodes making this manual one-off necessary.
package tv.ouya.examples.construct2.virtualcontroller;
- When building in
Construct 2
and exporting toHTML5
be sure to output to theConstruct2\VirtualController\www
folder so that the above command will pick up the files.
The In-App-Purchases example shows making purchases, checking receipts, adjusting the safe area, and exiting the app.
Open the InAppPurchases.capx
from the Construct2\InAppPurchases
example folder.
- The initial
Cordova
project was created with the command-line from theConstruct2
folder.
cordova create InAppPurchases tv.ouya.examples.construct2.inapppurchases InAppPurchases
Android
support is added to theCordova
project with the following command-line from theConstruct2/InAppPurchases
folder.
cordova platform add android
- Use the
Cordova
command-line to add thecordova-plugin-ouya-sdk
plugin.
cordova plugin add https://github.com/ouya/cordova-plugin-ouya-sdk.git#master
- To build and run the
In-App-Purchases Example
run the following command from theConstruct2/InAppPurchases
folder.
cordova run android
- Manually copy
plugins\cordova-plugin-ouya-sdk\src\android\MainActivity.java
toplatforms\android\src\tv\ouya\examples\construct2\inapppurchases\MainActivity.java
and edit the package name to betv.ouya.examples.construct2.inapppurchases
.Cordova
auto-configs cannot replaceXML
nodes making this manual one-off necessary.
package tv.ouya.examples.construct2.inapppurchases;
- When building in
Construct 2
and exporting toHTML5
be sure to output to theConstruct2\InAppPurchases\www
folder so that the above command will pick up the files.