Video hosted by Apple at devstreaming-cdn.apple.com

Configure player

Close

WWDC Index does not host video files

If you have access to video files, you can configure a URL pattern to be used in a video player.

URL pattern

preview

Use any of these variables in your URL pattern, the pattern is stored in your browsers' local storage.

$id
ID of session: wwdc2012-521
$eventId
ID of event: wwdc2012
$eventContentId
ID of session without event part: 521
$eventShortId
Shortened ID of event: wwdc12
$year
Year of session: 2012
$extension
Extension of original filename: mov
$filenameAlmostEvery
Filename from "(Almost) Every..." gist: [2012] [Session 521] Building Ga...

WWDC12 • Session 521

Building Game Center Games for OS X

Graphics, Media, and Games • OS X • 55:10

Game Center on OS X enables Mac users to compete with friends and fellow game players around the world, sharing the same social gaming network with iOS. Get a course of action for bringing Game Center games to OS X Mountain Lion and learn the best strategies for developing games that target both iOS and OS X.

Speakers: Gabriel Belinsky, Norman Wang

Unlisted on Apple Developer site

Downloads from Apple

HD Video (479.6 MB)

Transcript

This transcript was generated using Whisper, it may have transcription errors.

Good morning, everybody. We're here to talk about OS X, right? Game Center for OS X, specifically Game Center for OS X. Hopefully you've seen some of the earlier slides. Excuse me, Kristy, who just talked about multiplayer gaming, is awesome and one of my favorite topics because I think all games should be multiplayer. Well, we're here to talk about Game Center for OS X.

It's a little tight. It says, "Welcome back. I'm Norman." Well, actually, he's Norman. Norman will be helping me by coming on stage and showing a demo of Crush. You hopefully saw the demo two days ago. Yesterday. Yesterday in Dan's talk. So we've taken what Megan and Dan did and did a little OS X spin on it.

So welcome to everybody. Welcome back for me. Welcome back to my crew. We've been doing Game Center for a few years, and this is really exciting. because now we have it on OS X, and it's cross-platform, and it works with all the iOS devices that are out there now. You don't have to wait for iOS 6 for these features.

So as I mentioned, Game Center is new for OS X Mountain Lion. This is the first release we have for OS X, and we think it's great. It's the exact same community. So everybody who's been playing, I think there's 125 million users, something like that, have access, already have accounts, already have friends. So we can leverage that. You can leverage that when you're building your games. This is great. And, of course, multiplayer features. You can compete with all 125 million. And after this, maybe you'll have some insight how to create a game that works on both platforms to have the most fun.

So I'm going to be talking about the API that we're delivering. I'm going to be talking about the user interface that your users will be using. And I'm going to be talking about this from the context of OS X. So specifically, a little bit of a repeat here. Game Center API for OS X, what's available to you? How do you use it? We're going to show you a little bit about how to set up a project.

This is slightly new. It's similar to what you've done for iOS and how you get something into the iOS app store. We'll talk a little bit about the OS X app store, the Mac app store. Primarily, I'm going to try to focus on the differences between iOS and OS X. There's so much documentation out there now for Game Center. We've done presentations at WWDC for the last two years. All those are available online. There's developer documentation also on the developer site. And if we have some chance, I'll talk to you about some best practices when creating your games for OS X. So we'll go into this. Game Center as a whole is really comprised of exactly three pieces.

Game Center Services is large, but there's an application that the users use. There's the framework which you guys as developers use. And then there's the services which you need to -- which as a developer you use to set up leaderboards, achievements, group gaming, which is new, which will allow you to share your leaderboards and achievements across different apps. So they could be an app designed for an iPad and an iPhone and an OS X app. That's the new part of it, which is really awesome and it works today. And in fact, I've been told that some people are already trying it out, which is great. As developers, I hope you all downloaded the SDK. We're going to be around this afternoon and tomorrow in the lab. That's really your best resource. This slide is going to be online in a couple of weeks, a few weeks, I think. So let's talk about the Game Center app to start with. So I'm just going to give you a run through because if you're familiar with iOS, this should look identical, almost identical, right?

This is the page that you see when you log in. So you have access to change your status, your account, your photos. All the apps that are shown are top apps in the Mac App Store. So it allows better discovery. You want to be on your top app, and one of the ways to do that is Game Center, and we'll help promote your app. The other one is Friends. So you can see your friends, see what games your friends are playing, see what games in common you have so that you can actually go and invite him to play a game. There's also a couple sections. As you scroll down, you'll see OS X games. This is the new section, as well as what games are -- your friend has on iOS, which you can't see in this screen shot.

Then of course there's the game section. The top bar represents recommendations. These are all OS X game recommendations and shows all your OS X games here. Again, this screen is much larger and you can scroll through and see your iOS games. But you'll actually have the ability to look at your achievements, the leaderboards for each of the games compare similar to iOS. And then the request page. So in this case, Mikey has requested to be my friend and I can ignore him or accept it, it more friends, more games, more fun. We really like that. That in a nutshell was the app. But you guys are all developers, right? And you're really here to find out about the framework. Game kit framework.

It's even got the same name. So we've worked really hard to try to make the game kit framework on OS X equivalent to the GameKit framework on iOS because we assume that you've got some knowledge, some experience hopefully because you all have apps on the app store. And when moving to a new platform, we wanted to try to keep it as much the same as possible to ease your life. You'll see when Norman comes up, he'll show you some magic in Xcode and you'll see how similar it really is. So this might end up being a short talk because there aren't a lot of differences. But I'll go over an overview of the GameKit framework. We provide you UI for you to show leaderboards really easily. It's two or three lines of code. It's almost identical to iOS. The major differences you'll find is in OS X under AppKit you have a multi-windowed environment.

In iOS, it's a single window environment, and everything is presented modally on top of that. But here we see a leaderboard for our demo game with me up there. So I'm one of Norman's friends. That's great. Achievements, you can see the achievements inside your game. Again, really easy to do. And of course, multiplayer, my favorite feature. And here you can see Norman is just about to invite me to a game. But we'll get back to this. You'll see more in the demo. It's really cool when you get to see all this stuff live.

So the functionality of the game kit, this is just sort of a list of what you would want to do or what features we give to you that you can put into any game. So single player games can be more fun and more competitive if you add leaderboards and achievements. You don't need to have a multiplayer game to have competition. So we have access to players, players have profiles.

You can authenticate your players, the players have friends, you can see your players' friends, you can see your players' friends' photos, and of course leaderboards and achievements. Submitting achievements is the same, submitting scores is the same, there are subtle differences and we'll get into that. And of course there's all these multiplayer features. This is, I think everybody should strive to try to make multiplayer reality in your game. So, auto matching, the same auto match system. Invites work similarly.

And in fact, when you're going into group gaming and you've listed on iTunes Connect that you have a compatible game, when you send an invite, it goes to all of the devices that have that game. So, you can send an invite and receive it on both an iPad and a MacBook Pro, and you can decide where you want to play the game. That's really cool, and it works with all the iOS devices that are out there now. And I'll get into that a little bit. So peer-to-peer networking. You can set up a match, a GK match, as Christy eloquently described in the last session. How to communicate, how to check for player statuses, all of that is almost identical. And then there's voice chat and turn-based gaming.

So feature parity. I wanted to bring this up again because I want you to know how hard we strive to make it ideally the same. So if you've already got a game... that has these features on iOS. It's really simple, at least for the Game Center parts of it, to make it work on OS X. So players are a GK player, and authentication is handled the same, and it has the same properties as a GK player. We're feature parity with iOS 5 because Mountain Lion is shipping in a month, approximately, and we want it to work cross-platform right out the gate. So all of you with iOS 5 devices can join in the fun.

Leaderboard. So GK Score is identical. GK Leaderboard View Controller. Achievements. There's a GK Achievement Descriptions. There's GK Achievements. They're all identical. Submitting achievements is exactly the same. Matchmaking is handled exactly the same. So you have a GK Matchmaker View Controller. You present the view controller, we handle all the state transitions of sending invites, notifications, accepting invites, connecting people. So the multiplayer. Turn-based matches, exactly similar. And of course voice chat works across devices too.

There are, however, some differences. There have to be some differences. The biggest difference comes from the object hierarchies between OS X and iOS. And everything in iOS land uses the UIKit framework. And the UIKit framework gives you things like UI view controllers and UI images. In OS X, we're underneath the app kit. And the app kit gives you things like NSViewControllers and NSImages. In iOS, there's essentially one window, and everything is presented as view controllers stacked up on top. Whereas in OS X, it's a multi-windowed environment. So when you want to show one of our leaderboards or achievements, it actually is a separate window, and you can move it around. But what we've done is we've added a class. So these are the differences, pretty much the only differences from a Game Center perspective between iOS and OS X. What we've done is we've provided you with this class. It's called a GK dialog. And you can use it in a very similar manner to you would as a root view controller in iOS so that when you want to present one of our UI elements that we give you back as a GK leaderboard view controller, you can use this. And it's really simple, right? So you can allocate a new one. You set the parent window so that when you present the view controller, it shows up in the right spot. And then we provide a present and a dismiss method.

Of course, when Norman actually gets to do the demo, you'll see this in play. He does a little Xcode magic. It's kind of cool. If you're using one window, you only need one dialog controller. If you're using multiple windows, you'll want to have multiple dialog controllers. In our case, we have a single window game where the game itself is in one window and all the methods to bring up the leaderboard and the view controller all come from one main menu in our game. And so it's easy in our case. We just have a single dialogue view controller, a dialogue controller. And there's one thing that I've been asked to mention.

This is not Game Center related, not entirely Game Center related, but early on when we released GameKit Framework on iOS, before we introduced Game Center features, we had these two classes. It's called a GK Session and a GK Peer Picker Controller. And we used these to connect players together and browse for players to play with and communicate.

So what we're telling everybody to do is, for best practice, use GKMatch and GKMatchMakerController. At the end of the session, if I have some time, I've prepared some slides to talk a little bit about the GKMatch and the MatchMakerViewController, but the best resource was... No, an hour ago. But as I said, all the videos are going to be online, and you should review that. And there's quite a lot of documentation. We talked about it last year as well. Things haven't changed. And then the last piece is Game Center services.

Game Center Services is all the servers that hold the leaderboards and the profiles and the profile pictures and the achievements and things like that. And it interacts quite closely with iTunes Connect. iTunes Connect is where you go to enable your game for Game Center. So you set everything up there. You're going to say what leaderboards you're using, what achievements you have. And this is a new piece where you define the game groups. So Dan talked a little bit about game groups. Christy talked a little bit about game groups. There's the iTunes Connect session, what's new in iTunes Connect this morning, where they talked a little about game groups. That's where everybody probably is because they're doing a repeat.

And multiplayer version compatibility. So previously you were only allowed to have version compatibility with the same bundle ID. Now we allow you to actually have version compatibility across bundle IDs. This allows us to have OS X games play with iOS games. And I think that's really, really cool. So now that I've sort of told you about everything, I want to talk about how you actually create the game. So it's a little bit more involved.

If you're coming from OS X, you can't just compile and go. You'll need to get a certificate. you'll need to deal with the developer site. So the first thing you want to do when you're getting started up, and this will be familiar to everybody who has iOS experience, particularly getting things into the store. So you go to the developer site. This is where you register to get a signing certificate, where you get all your provisioning profiles.

So first thing you do, you go to the dev site, you set up an app ID. Once you've set up the app ID, you configure the app. In our case, we want to say what machines we're going to be doing our testing on. You need an entitlement for Game Center. This is the new piece, which is the main reason for going through here before you actually test. You need to sign your apps either with an ad hoc certificate -- sorry, profile. So when you go get the profile, you'll get two profiles, right? You'll get one so that you can share and beta test your apps, and you'll get another one that you sign for submitting to the store.

So here's the screen that you'll see, or part of the screen, when you go to configure your app ID, there's a new section that says "Enable for Game Center." So when you check this box, what happens is it will put the Game Center entitlement into the provisioning profile. So when you actually sign your apps, then you'll have access to talk to the Game Center servers. If you fail to do that, you'll see something like this. And it's a little bit small, but it says, "Could not connect to Game Center servers." And this might happen for a number of reasons, but one of the reasons is that you're missing the Game Center entitlement. And you'll see also in the logs, if you're looking, that you've been denied. So make sure that you go and you check that little box and you get your-- at least an ad hoc provisioning profile so that you can sign and test your games. The second piece that's important, well, you can kind of test at that point, but there's not much to test to. You want to configure your app for Game Center, and you do this at iTunes Connect. So this is sort of the main screen of iTunes Connect, and there's a button that says-- well, it's a link-- "Manage your applications," right? So when you go to manage your applications, right, you create a new app, well, we're here to talk about OS X, right? It's almost identical.

It looks very similar to the iOS app one, but we're here. It's OS X. This is the screen that you get once you've set up your game for the first time with your bundle ID that's been blocked out. But really what I want to focus on, I want to focus on two things. I want to focus on this one first, which is Manage Game Center. This is configuring Game Center for the bundle ID. So across all versions of that bundle ID, it's mostly a place where you go to set up leaderboards and achievements and define your groups. The other section, I'll get back to it in a minute, is the version. And there are some things that you need to be aware of that you need to do for each version that you're uploading to the store. So here's the new screen, right? When you go to an Able game center for the first time, you're asked, "Is it a single game or is it a group of games?" And the group of games is new. And even if you pick single game, or if you have a game that's already in the store, which is a single game, you'll have the ability to add it to a group later. But this is your first sort of, "Ooh, this is new. This is cool." Group gaming really is cool. Group games, games of groups, right? Because it allows you to share leaderboards and achievements. Multiplayer functionality, which is the coolest part. So here we can see what happens. You actually configure your game, you add leaderboards, you add achievements. There's better places than here for me to describe this. The iTunes Connect documentation. But really what I wanted to focus on is this. you need to have your Game Center game enabled. Click that button. And here you can see, for instance, you also have the ability-- this is a single game screen-- to move it to a group. So if you accidentally press the wrong button or you have an older app that you want to migrate, this is where you go and you do it.

And then the other thing that I wanted to talk about is the version that you're about to upload. So when you actually view the details when you're preparing for upload, it gives you a screen that looks something like this, where you put in the version number and you define all your app ratings and the categories and things like this. And really what I want you to notice is the version number at the top. So for everything to work seamlessly, you need the version number that you're submitting to the store that you're building to match-- the version number -- sorry, excuse me, the build number inside Xcode. At the bottom is where you define -- and here we have another enabled game center.

And this is per version. So you have to do this for every version of your game, not just for the overall game. You have to do that, too. But that's sort of another caveat. And here you can see I have some leaderboards set for my group. There's a global leaderboard. a few achievements, and this is the cool new part that I like to talk about. You'll see there's two games in there in the multiplayer compatibility side, right? There's an iOS game and a Mac OS X game. And we'll show you that it's fairly easy to make that work. But this is a new thing, and I hope to see lots of great games.

If you're missing versions, for instance, again, it's kind of small at the top, it says, "This game is unrecognized by Game Center." This will happen if the Xcode bundle ID doesn't match with the iTunes Connect bundle ID, if there's a version mismatch, something like that. But just to give you a sort of heads up. Before I throw it off to Norman, which I will do in an instant, I just want to talk a little bit about what he's going to show you.

So we're focused on Game Center, so the demo is going to be focused on Game Center. We're going to talk about how to make a single source work on both iOS and OS X, but we're only focusing on the Game Center portion. There are lots of other things that you're going to run into when trying to do cross-platform on any platforms, but particularly our platforms. You're going to want to take graphics into consideration. You're going to want to take input into consideration. You're going to want to take sound into consideration. So touch on an iOS device doesn't exactly map to touch on an OS X device. So we've done some of that. We've prebaked some of that, right, so that we actually have a game that works. And we're just going to be focusing on the differences between the GameKit framework on OS X and the GameKit framework on iOS.

In particular, so I mentioned it before, the hierarchies are different. So in one case you get a UI view controller, in one case you get an NS view controller. And we'll show you how to use the dialog controller. We'll talk a little bit about images. And the one compilation defined that you're going to want to use is target OS iPhone. And this is true on all iOS devices. So it's true on the iPod touch, it's true on the iPad, it's true on the iPhone, it's not true on any of the OSN platforms. So you'll see how we use this to differentiate in our single source so that we have code that only compiles on one side or the other. And I believe this is where I ask Norman to come up and show us some stuff. Hi, I'm Norman. So I'm going to be doing a quick demonstration of how easy it is to bring an existing iOS app with Game Center enabled into OS X. So the application we're going to be using is called Crash, which is developed internally by Apple. Most importantly, it's got Game Center integration by using GameKit framework. So I'm going to go ahead and switch to my demo machine. Here in Xcode, before we dive into the actual coding, I'm just going to have a quick run of what Crash looks like for those of you who haven't seen it. So this is the iOS project. I'm just going to run it in the simulator. Here we go, Game Center integrated. I'm logging back in. It has leaderboards. I have achievements. And the single player, this is a typical vertical scroller slash shooting game.

And there. Okay. So we are going to be bringing this game into OS X in terms of graphics, input, as well as audio, and lastly, the game center portion. So we go ahead and create a project which is targeted for OS X. Right now we have a separate iOS project and now we create a new project called OS X. We have done quite a bit of homework, so I'm going to go through what we have done. So we have set up the version number, which is matching with the iOS version, and also we have set up the bundle ID, we have the correct provisioning profile, which allow us to use Game Center, and we have also added the dependency of the GameKit framework so that we can use the GameKit integrations on the OS X. So I will briefly touch three big areas of what we have done in terms of the bring over. So the first one is graphics. So the graphics, there's some differences running on embedded devices versus the desktop device. On the embedded device, we have OpenGL ES that's available to us. But on the desktop, we have the full blown OpenGL core profile that's available to us. So what we have done is we built an abstraction layer that will issue -- translate a draw call that you're issuing into corresponding GL draw calls versus GL ES draw calls.

For example, if you do draw aliens, it will do the right thing based on what platform that you have. So for the scope of this presentation, we're not going to be going into every single nitty-gritty details of what we have done in terms of bringing the graphics over, but we also have dedicated GL sessions as well as open GL labs that's available, you're welcome to drop by and have a look at those. Also, in terms of graphics, we do not have any PBRTC texture compression for our games, which makes the bring over fairly easily. In terms of audio, we use open AL, which is also available on the OS X that make bring over fairly easily.

It's the same framework. And I want to talk about input. So this is when... you as a developer can get-- can be creative in terms of creating the right solution. So for Crash, as you can see in the simulator, we basically hold down the single touch on the screen so you can move around as well as performing the shooting. So you can be creative and be-- bring the best look and feel of the OS X native app. What we have down here is we actually hook up to the mouse events, so when you click down the mouse, then you can move left and right. But some user might prefer, if you're coming from a first-person shooting experience, you might want to hook up to WASD or error keys in order to feel better or be detached away from the mouse.

Okay, so let's look at the next one. The code here. So there's some fundamental differences as what Gabe mentioned. One of the big ones is the difference between app kit versus UI kit. So here we have a declaration of the UI view controller. By the way, I'm gonna be working in my menu.h and my menu.m file in our project. These are the primary file that deal with or creating the UI of the game, and these are the only places that we have that deal with the game kit APIs. So here we are in the header file. We have a declaration of UIViewController. We type that to view controller. Which is not going to be working for us for OS X because we don't have UIKit. We have AppKit instead. And the way we use this view controller in our game is to bring up any of the associate views. for example, achievement view or leaderboard view on the iOS side. As Gabe has mentioned in his previous slide, we do have a GK dialogue controller that's available on the OS X, so we're going to be using that to present and dismiss any of the leaderboard or achievement view. So let's go ahead and add that into our class. So if we are on iOS, let's keep the decoration of the UI view controller, because that's what's available and that's working for us. Otherwise, on RISC-10, we declare a new property called GKDialogController, which we'll be using for translating the presentation and dismissal of any of the view controller we bring in and out from the GameKit framework.

So that's that. Let's switch to... the source file. So now we have a whole bunch of compilation errors. So when you look at this, as soon as we have a declaration of different properties based on different platform, we need to change the synthesizers so the right instance variable can be created. So instead of doing synthesizing just the view controller, let's do if we are on iOS, let's synthesize view controller. Otherwise if we're on Mac, because we are declaring the dialog controller as one of the properties. Let's synthesize that one. Okay, so what we have so far is on OS X, view controller is no longer available to us, and we use a GK dialog controller instead. But we can't really use it right now without any initialization, so let's go ahead and initialize this for the OS X. So in our view initialization, let's do this. If we are not on iOS, so which means we are on OS X, the GK dialog controller can be created by calling the standard alloc init, and we're setting up a single property, which is the parent window. This is easy for us. Crash is a single window game, so therefore we can always retrieve the window by doing the self view window that will give us the one and only window that's available to us, and that.

Okay, so we have a dialog controller at this point, and it's initialized and ready to go. And now it's coming down to how we present and dismiss any of the view controllers from GameKit. And you can see we have all these iOS-specific code that we will need to do some refactoring.

So to do some refactoring, I come up with a generic present and dismiss method that's available on both platforms. So when you call it on the iOS side, it will be automatically calling the ViewController, present, and dismiss any of the ViewController you want to bring up. But on the OS X, it will just use the GKDialogController to present and dismiss the ViewController. Let's go ahead and say if we're on iOS, our present view controller. Notice how we're declaring a UI view controller here. That's UIKit that's available on the iOS. So the body will be the existing code that we have. So we use the UI view controller to present a model view of the GameKit controller. And for the corresponding dismiss, again, we're doing a UI view controller.

and it will be calling the view controller directly dismissal. On the OS X, since we have declared GKDialogController, and that's available to us and has been initialized, so we can go ahead and use that. And for OS X, because it's AppKit, and we are switching to an SPU controller here. So we use the GKDialogController calling the present view of the input view controller here. And for the dismissal, we are gonna be doing the same thing of using the GKDialogController.

All right, so with this block that's in our code right now, we have two functions that's available for iPhone and OS X. And it will behave differently, but it's the same interface of calling in and out from your code. So let's go ahead and start using these new functions and put them into our code.

All right, so we have a couple of places doing view controller dismiss and view controller presentation, but if you notice this code, this is our existing iOS code. What it does is because iOS is single window and it's full screen, everything is presented modally and in order to bring up any of the model view controllers, you need to dismiss any of the previous one that's being brought up. So we're doing this failsafe tag here previously, but it's no longer needed for OS X because we're dealing with multi-window environment. So let's make that iOS only.

And for the completing our new code refactoring, let's go ahead and start using the new dismiss method, because this has been factored out. So, I already have that in. Remove that. And this is actually a self.viewcontroller. And for viewcontroller presentation, we have created a present viewcontroller. So let's go ahead and use that. And this is the second dialog controller when invite happens. So we'll go ahead and make this iOS only. That's dismissing any of the model view that's already presented. Let's use the dismiss view controller here.

and view controller presentation, let's go ahead and use the new function that we created, which is cross platform. Copy that. And here you see how we show leaderboard, which is the old iOS code. Change that to use the new code, which is for both platforms, show achievements. Let's do the same thing for present view controllers.

And after we authenticated matchmaking controller, we are going to be using the new present view controller. And here, any of the view controller that's finished being interactive with the user will perform a dismissal. But let's go ahead and use the new dismiss view controller function that's available to us. So here, this is the code to dismiss the achievement view. And here, dismiss the leaderboard view, dismiss matchmaking view controller, and again, matchmaking view controller. So now we have finished making these changes. All right, build succeeded. Let's go ahead and launch that.

All right, so this is Crash running on OS X, and you can see it's logging me in automatically. And from Game Center, I'm logging in here. My profile photo is showing, and I have one and only friend of Gabe right here. Crash is on iOS. The implementation is a peer-to-peer multiplayer game. This is the most important part. So after, yeah.

So the leaderboard is now being presented. It's the same chunk of code. PresentViewController and DismissViewController is running on both platforms. So now achievement also works. And how you notice... These views are actually independent windows, which is different compared to OS X. I'm going to go ahead and send an invite to Gabe, who's going to be running the very same app running on his iPad. Let's see if we can do a cross-play. OK, invite friend, one and only. Hey, be nice to me. I'm a good friend to have.

That's a good thing. We're connected and ready to play. Press play. There you go. I'm green, he's red. Yeah. It's fairly easy and fairly straightforward. But you see how I am at a disadvantage here, or maybe Gabe is being merciful. So I'm using a mouse here, and immediately I notice the input that we're using, it's-- putting me in such a disadvantage. But what I can do is I can always duck behind Gabe, so letting him take the bullet. But as you can see, you can be creative here and start using some more better method of handling input. On the UI view controllers on the iOS side, you basically just limit it to touch events. But on the OS X, you have mouse and keyboard, and you can hook up different delegates and listen to different events in terms of keyboard and mouse.

So that's... That... Okay, so what do we have here? We have a single set of source file that's being available for both projects. So let's go back to iOS project, and you can see the changes that we have made are propagated to this project because they share the same files. Let's just make sure we didn't break that for doing any cross-platform work. it's always good to verify on both platforms. All right, because we changed the view controller presentation, this missed, and these are still working.

And no problem. All right, so last week when Gabe and I worked together, and Gabe came up with this crazy idea saying, "Oh, you know, with Crush launching that "after you log into Game Center, "we have no any acknowledgement for the user "to know that you're logged in." So he said, "Why don't you just load the player profile photo "and put it on the screen somewhere?" So we're going to go ahead and do that.

So let's switch to OS X project. So now let's develop on OS X. And GKPlayer actually gave us this functionality. So if you look at the GKPlayer, there's an API already, existing API, got little photo for size. Everything is looking exactly the same except this guy. So on iOS, it's a returning user, a UI image pointer in a callback block, but it's only having an NS image on the OS X. So we need to bridge the gap here. And from this point, Any code that we write should always have the mentality of having to run on both platforms. So ideally, I would only want to write this code once, having the logic set once, but it works magically on both platforms. Okay, so let's figure out where we need to stick that code in first.

So in the initialization, we're authenticating with Game Center. So at this point, we have a login result. Whether it's success or failure, we are doing different things. So here would be a good place to put in that code to perform a load of player profile. So let's say we load the player profile and put it on the bottom right corner of the screen. So how do we do that? That's easy. We just call the API. It gave us the image. But how do we put an image on the screen? We need to put an image to some sort of image view and put that image view on the screen as a subview. Okay, but on iOS, we have a nice UI image and UI image view, but on OS X, we have an NS image and NS image view, which is quite different. So to bridge the gap, I'm declaring a new prototype called picture or profile photo. So let's go ahead and do that. If we are running on iOS, I'm going to tap that UI view to a profile image data type, and also I will type dive UI image view to profile image view.

Otherwise on OS X, I'm gonna go ahead and use NSImage instead for this data type. I use NSImageView for... this profile image view. So which is good. So what do we have here with this chunk of code? We have two new data types in our game, which is in our code base, which is profile image, which is a generic image type, and profile image view, which is a container, generic image container for this. So on different platforms, it will give us the same functionality.

So we can go back to this code and start loading our image. So to load image, we find a local player, which is the player that's always logging in. And then we call the load photo for size, specify a small. And notice the callback block here. Instead of taking the NS image or UI image, I'm using the brand new data type I have created above.

So if the photo is set and loaded, we're going to define the dimension of the photo we want to display to be 64. And we create this photo image view. We need to set where it's going to be locating. So for the bottom right, so the x axis will be the total width minus the dimension, and y start at zero, and we want to display as a box, so it's the same dimension. So once we have the dimension and we have the image view, we need to set the image property to be the photo that's being returned to us by GameKit, and we also set a frame, which is the location, and we add that to our game view. So it will be overlaid on top. And we close that. On OS X, let's go ahead and run that. Okay, so now I'm logging in. Profile photo is loaded and displayed. So let's--for sanity check, let's go back to iOS project, builds, and let's load up the simulator. And it's working some sort. And what do we have here? We have a iOS-only bug.

The gotcha here is the difference between UIView and NSView. In the UIView, the origin of... the view starts at the top left corner. However, if you switch to OS X using the NSView, it's on the bottom left. That's your origin. So there are a couple ways to solve this. You can apply a transform to your view just so that all the coordinates are exactly the same across different platform.

Or you can invert the math by setting -- take the difference on the approach when calculating the y-axis. So let's go ahead and do that. So we are in the iOS project. So here's the code that we have loaded. And for OS X, we want the y-coordinate to be zero because that's when the bottom starts. Let's change that. So if we're on iOS iPhone, the height of where the y-axis should be, the total height minus the picture dimension. Otherwise, on OS X, we just use zero. So now let's build that and have a quick run-through. And here we go. We invert it, and now the bug is fixed. And OS X should not be touched.

Here. So we have feature parity as well as fixing the bugs on the iOS-only side. And I'm logging to Game Center. So let's look at the games. And I have Crash that's under me. And these are my achievements, which have completed. And if you look at the achievement over here on the iOS side, they are exactly the same, which is quite cool. And you get that for free by using-- by adopting the GameKit framework. And using GameGroups. Yes. So that's the end of the demo, so hopefully you get an idea of how easy it is to bring the equivalent GameKit functionality from iOS to OS X. And now I'm going to switch back to Gabe. So I think Norman did a great job, especially showing how easy and similar the two platforms are from the GameKit framework. We showed exactly how to deal with the UI view controller and the NS view controller. We used a GK dialogue controller instead of a root view controller. Images pretty much the same. There's a convenience here. It just so happens that the relationship between an NS image and an NS image view is the same as the relationship between a UI image and a UI image view, so that made it really easy for us. But you also notice some of the difference. So the graphic coordinates, for example, are different between the two platforms. And then, of course, we saw that target OS iPhone show up quite a lot. It's probably really important. I have a few minutes left. And as I mentioned before, I talked a little bit about this old API that existed for GK session. but I really wanted to talk a little bit about peer-to-peer multiplayer. I know Christy did a fantastic job, so I'm just going to go over this briefly, and then I'll try to summarize it. I don't have much time left. So to get a multiplayer game going, it's fairly easy.

You have a match request, a GK match request, which defines all your match parameters, how many people are in their game, if you have any special matching attributes or you want to divide your players into buckets. There's a GK matchmaker, which is a singleton, which you can use to do a quick match. You set an invite handler there. There's a GK matchmaker view controller, which is the UI. So you saw that in the demo where Norman invited me. That's the GK matchmaker view controller. And then, of course, the GK match, which you use to communicate between your different players. So I think I have three slides on this. The first is the GK matchmaker view controller. And that gets created basically in two ways. with a match request if it's an outgoing match, or with an invite if your user has accepted an invite, launches your game. If you set the invite handler, you'll get this invite. And you need to create the view controller. And of course, displaying it is just subtly different. It's still only a line. Really easy to do. The objects that you get back, the GK Matchmaker view controller is still a GK Matchmaker view controller on both platforms.

but use the dialog controller in our case to present it. How you actually get a GK match is one of two ways. Either as a delegate from the GK matchmaker view controller, so when the invite has been successfully made and the-- The games have -- the two devices have connected to each other. All the players show ready. You press the play now and we give you the match back. The other way is I called it quick match, right? It's just a quick way to do matchmaking.

You can't do invites through here. So you set up a match request. You find a match for the request. And on success, we'll give you a GK match back. And what do you actually do with the GK matches? you send and receive data. As Christy mentioned before, you can send data either reliably or unreliably, and you can either send data to a list of players. In this case, I picked all the players in the match, but that's not necessarily what you want to do. Or you could send data to all the players, which is really doing a broadcast. Receiving data, this method is a delegate callback. So when you get that match, you set up yourself as a delegate, and you get these callbacks. And this provides a lot more functionality than GK Session ever did, because now you have players, and there's a community, and you have achievements, and leaderboards, and so there's no reason to miss GK Session at all. What we really did was we showed the differences in a very interactive way between OS X and iOS. And so I just wanted to talk about some of the issues that you're going to find when you're trying to write a project that's cross-compatible. The first one is obviously the Xcode setup. We didn't really have a chance to show you this. What we did have is we had two different projects. You don't actually have to have a separate project.

You can do it as a separate target inside your main project. Some people find that easier. I find it a little bit easier to have two distinct projects, right? So maybe I can have them open at the same time. You want to import your code as shared code. So you don't want to make a duplicate of your code, because then at one point you're going to get forked in the differences, and it could be a mess. And it's really easy to use the conditional compilation to target one or the other platforms in a single line of code. Norman touched on this briefly, is input handling. So one of the interesting things about the iPad and the iPhones With the touch input, you can do lots of cool things. And we've been standing here for years telling you about how we want the input to be different. Make it innovative. Make it interesting. Use all your creativity in defining interfaces for games, because it's a really different platform. And now we're telling you, "Well, okay, we want it to work on both platforms." And so, you know, it's not necessarily the most simple thing. And so you have to take these into consideration when you're building your game. How is it going to work with a keyboard and a mouse? Or how is it going to work with a Bluetooth controller?

Right? Well, just some things to think about, right? We mentioned the OpenGL or audio. There are differences, certainly. One of the other issues that we didn't talk about was byte size issues. iOS is primarily a 32-bit platform. On OS X, you can either do 32-bit or 64, but there's a whole host of reasons you're going to want to compile your projects as 64-bit. But when you do that, some of your data types are going to change. So a void star pointer isn't the same on both sides. Integers aren't necessarily the same. So other things that you'll really need to think about. So for instance, we use an NSData to pass data across multiplayer. But you'll need to sequence your data, serialize your data, and un-serialize it on the other end. And we really leave that up to you to make sure that, you know, you get it right. In summary, this is time for me to wrap up. We really talked about what it is you need to set up your project.

Hopefully at this point everybody's downloaded the developer preview and have done this at least once, right? We've also talked a little bit about what things you need to make sure of you've done on iTunes Connect. So the enabled game center for your game, enabled game center for the version, setting up your leaderboards and achievements, a little bit about the Xcode. We showed you some code, and we went through all the UI and API that you'll see, right? And that's it. Alan, awesome guy, helped us set this up. He's been doing wonders for us all week. He's the main evangelist for games and graphics, an awesome guy. The developer site, that's where you get all your provisioning profiles.

But also it's a wealth of information. All the developer documentation is there. All the presentations have been recorded from years past. These ones are recorded and will show up there in a few weeks. So if you missed them, go tell all your friends, because I certainly don't see enough people here. And then the forum. So communicate amongst yourselves. communicate with us.

I know a lot of the engineers regularly go through the forums. It's a great place to get help that's not read-only. Related sessions. Yeah, I'm lost, so these all happened before me. But videos will be available. I know that the presenters will all be available. Thank you, everybody, for coming.