Adobe Native Extension for iOS Game Center – Part 2

In part one of this series, you created the Actionscript 3 library, Objective C static library and wrapped it all together in a beauteous Adobe Native Extension (ANE) for use in your Flash mobile app. By now, you’re able to connect to Apple’s Game Center, but you don’t know it yet. This post will will show you how to make use of your ANE to invoke the loginUser, showLeader, and showAchievements methods in your native library.

At this point, you should have created the BazingaANE.ane (or whatever you named yours) and you’re ready to use it in your app.

The full code is located here on Github.

Start up Flash Builder 4.6 and click File -> New Flex Mobile Project, give it a name of “BazingaGameCenterTest” and click next. We only need to target the iOS platform, and we’ll use a View based app, then you can just click the finish button. Now we’ll add the ANE to the project. Choose Project -> Properties -> Flex Build Path -> Native Extensions -> Add ANE, then browse for your BazingaANE.ane you created in part one.

Before you close the dialog box, navigate to Flex Build Packaging -> Apple iOS. You’ll need to add your certificate and provisioning file like usual for iOS apps. Once you browse those files, take a look at the Native Extensions tab in the same dialog box. You need to ensure the package checkbox is checked, and you may want to add your Apple iOS SDK path in the textinput below. Once you do that, click the finish button.

Sample app to try your new ANE

The Actionscript 3 code is simple once everything is set up properly. You call methods in the ANE just as you would any other AS3 library.

<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
title="Home"
viewActivate="init(event)">

<fx:Script>
<!&#91;CDATA&#91;
import com.pxldesigns.bazinga.BazingaANE;

import spark.events.ViewNavigatorEvent;

protected var bazinga:BazingaANE = new BazingaANE();

protected function init(event:ViewNavigatorEvent):void
{
bazinga.loginUser();
}

protected function showLeader(event:MouseEvent):void
{
bazinga.showLeader();
}

protected function showAchievements(event:MouseEvent):void
{
bazinga.showAchievements();
}

&#93;&#93;>
</fx:Script>

<s:layout>
<s:TileLayout paddingBottom="10"
paddingLeft="10"
paddingRight="10"
paddingTop="10"/>
</s:layout>

<s:Scroller>

<s:TileGroup width="100%" height="100%">
<s:Button label="Show Achievements"
width="200"
height="200"
click="showAchievements(event)"/>

<s:Button label="Show LeaderBoard"
width="200"
height="200"
click="showLeader(event)"/>
</s:TileGroup>

</s:Scroller>

</s:View>

If all goes well, you should be able to run the app on your device without any crazy errors. When the app starts up, you should give it a second and you’ll see the GC welcome modal view pop up. After that happens, you’re looking at the easiest game you’ll ever play on iOS. The two buttons just show the achievements and leaderboards you set up in iTunes Connect, it should show your game’s logo and any achievement information you entered in iTunes Connect. I used my Game Center sandbox account along with some others to increase the scores for Bazinga, so I can see the multiple accounts on the leaderboard. After this exercise, you’ll have the general idea for the full implementation of Game Center with your ANE. You can move on to submitting scores, and achievements and all the other fancy stuff you can do with Game Center.

Where to go from here

There are approximately a billion things that can go wrong when creating your ANE. There are three different projects (AS3 library, AS3 test app, and Objective C static library) and a ton of other scripts and processes that can cause havoc if any one step is missed or if some setting is wrong. This two part series assumes that you’re very familiar with creating new apps with the iOS Developer Portal, setting up Game Center leaderboards and achievements in iTunes Connect, creating Obj C static libraries, AS3 libraries, ADT, and so on.

I will keep updating these posts with any new information, as well as the Github repo. If you have any feedback, as always, feel free to share. Keep in mind, this ANE by itself is no good to you because my provisioning file won’t let you run the app 😉 You need to create your own, but the best way is to grab all the code from Github, read through step by step and bang your head against the desk like I did until you succeed in building one of your own. Pay very very very close attention to detail as the whole process can induce major headaches for the simplest stuff.

I’m looking forward to seeing some awesome Flash games on iTunes with full Game Center integration very soon 🙂

Helpful links and shout outs

The best blog posts that helped me understand the whole process of ANE creation and working through the bugs were liquid-photo.com  flashsimulations.com custardbelly.com and tutsplus.com Special thanks for the great work!

Adobe LiveDocs

Adobe Beautiful Code

Facebooktwitterlinkedin

5 Comments

  1. Marc Pelland

    Thanks for these tutorials, they have really helped me wrap my head around the creation of ANE’s. Still trying to get the submission to Game Center down, but not bad for a half hour of setting things up. Again, much appreciated.

  2. Dave (Post author)

    Hey Marc,
    No problem, I hope the posts help. If there’s anything unclear, just give me a yell as I plan on going back and editing both of them to clarify any “iffy” parts.

  3. Zener

    Any chance for a new vervison that doesn’t require MacOS?

  4. Dave (Post author)

    @Zener, what are you using to develop with?

  5. Leonardo

    Catching Zener’s post, I’m on a windows machine, using flash IDE.

    But well, I will bang my head too to get everything sorted on windows. Your detailed posts and links helped a lot. Thanks!

Comments are closed.