Skip to content

Instantly share code, notes, and snippets.

@gamebuilderstudio
Created February 13, 2014 00:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gamebuilderstudio/8967536 to your computer and use it in GitHub Desktop.
Save gamebuilderstudio/8967536 to your computer and use it in GitHub Desktop.
This code can be implemented in the generated base project from GameBuilder Studio if you want to handle the Ouya product purchase logic yourself via code.
package
{
import com.gaslightgames.nativeExtensions.AIROUYAFacadeANE.AIROUYAFacadeANE;
import com.gaslightgames.nativeExtensions.AIROUYAFacadeANE.AIROUYAFacadeANEEvent;
import com.gaslightgames.nativeExtensions.AIROUYAFacadeANE.Product;
import com.gbs.game.screens.BaseGameScreen;
import com.pblabs.engine.PBE;
import com.pblabs.engine.core.LevelEvent;
public class GameScreen extends BaseGameScreen
{
public var ouyaFacade : AIROUYAFacadeANE;
public function GameScreen():void
{
super();
//Setup Custom UI Elements In This Class
//You will need to at least initialize the Ouya plugin inside of GBs so that the native extension is included in
//the final build
}
/*-----------------------------------------------------------------------------------------------------------
* Public Methods
-------------------------------------------------------------------------------------------------------------*/
override public function onShow():void
{
super.onShow()
//Implement if needed
}
override public function levelLoadComplete(event : LevelEvent):void
{
super.levelLoadComplete(event)
//Implement if needed
purchaseOuyaProduct();
}
override public function levelPreLoad(event : LevelEvent):void
{
super.levelPreLoad(event);
}
public function purchaseOuyaProduct():void
{
if( AIROUYAFacadeANE.isSupported)
{
this.ouyaFacade = AIROUYAFacadeANE.instance;
this.ouyaFacade.addEventListener( AIROUYAFacadeANEEvent.PRODUCT, onProductInfoLoaded );
this.ouyaFacade.requestProductList( "your-product-id");
}
else
{
trace( "OUYA ANE is NOT supported." );
}
}
public function onProductInfoLoaded(event : AIROUYAFacadeANEEvent):void
{
this.ouyaFacade.removeEventListener( AIROUYAFacadeANEEvent.PRODUCT, onProductInfoLoaded );
var products:Vector.<Product> = this.ouyaFacade.getProductList();
var i:int = 0;
while( products.length > i )
{
trace( "Product " + i + " is: " + products[i].name + " and costs: " + products[i].originalPrice );
i++;
}
this.ouyaFacade.addEventListener( AIROUYAFacadeANEEvent.PURCHASE, onProductPurchase );
//Execute the product purchase once the data has been loaded from the Ouya server
this.ouyaFacade.makeProductPurchase( products[0].identifier );
}
public function onProductPurchase(event : AIROUYAFacadeANEEvent):void
{
this.ouyaFacade.removeEventListener( AIROUYAFacadeANEEvent.PURCHASE, onProductPurchase );
if(event.status == "SUCCESS")
{
//Purchase was successful
//Give player access to more game play
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment