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: wwdc2011-407
$eventId
ID of event: wwdc2011
$eventContentId
ID of session without event part: 407
$eventShortId
Shortened ID of event: wwdc11
$year
Year of session: 2011
$extension
Extension of original filename: m4v
$filenameAlmostEvery
Filename from "(Almost) Every..." gist: [2011] [Session 407] Introductio...

WWDC11 • Session 407

Introduction to Game Center

Graphics, Media, and Games • iOS • 55:37

iOS games can take advantage of Game Center, Apple's social gaming network. Get introduced to the concepts behind this technology and understand how to create a gaming experience that users find compelling, fun, and easy to use. Learn the approach for adding Game Center to your games and get an overview of the classes and APIs in the Game Kit framework.

Speaker: Nathan Taylor

Unlisted on Apple Developer site

Downloads from Apple

HD Video (178 MB)

Transcript

This transcript was generated using Whisper, it has known transcription errors. We are working on an improved version.

Hi. Welcome to the introduction to Game Center. I'm Nathan Taylor. I'm the engineering manager of the Game Center team in iOS engineering. And I'm going to talk to you today all about Game Center and how you can get Game Center on in your games. First, a little overview of what Game Center is. Game Center is Apple's online social network. It's been available since iOS 4.1.

That's about nine months ago. A year ago, basically on this stage, we presented Game Center as a developer preview. We got a lot of interest and excitement. We've seen some great games since it released with iOS 4.1. Game Center provides several features to make the gaming experience more social and more competitive and more interesting.

One, we have online leaderboards, which really allow players to compare the best scores against their friends and against the best players in the world. We also offer integrated achievements so that you can reward your game players for exceptional gameplay. You can give them -- let them track -- you can track and reward their progress, you know, and let them really feel that they've accomplished something in their game. You know, a lot of people want to go and get all the achievements in the game. There's an achievement for beating every level of the game that I know people that will go and try to get it.

And then we had a big feature called multiplayer gaming, and this also came with voice chat. And this allowed people to compete online and communicate in their games. And it's been really great to see some of the awesome multiplayer games that have come out. And Game Center itself provides many avenues for promotion and discovery of your games. And just one of these is the friends list and friend details where you can see what your friends are playing. Since we released, we now have 50 million Game Center users.

This is a massive community. We also have many of the top games selling in the App Store today are Game Center enabled. And we really want all the top games to be Game Center enabled. There's been a ton of activity in Game Center. We've got a lot of users doing a lot of different things, and we'd really like to see them playing your games.

[Transcript missing]

Game Center is delivered in three parts: the application, which is the user-facing front; there's the GameKit framework, which you are going to use the API from in your application; and then there's the Game Center services that manage all of these users that we have, and all of the data, the leaderboards, the achievements that they submit and they've earned. And we tie all these together in Game Center, and you get to it through the GameKit framework.

We're going to start with the Game Center app, get a brief overview of what it provides and what's new in iOS 5. The Game Center app is the built-in app for social gaming. It's a feature built into all iOS devices we sell today. It provides most of the basic services.

It starts off with account management. We need the users to create their Game Center account. They can also manage their account, change settings. But the more interesting features are how they can use Game Center to browse and discover their friends and make new friends and build this great friend graph that we have. And for you guys, how they can browse and discover your games.

And we really hope this -- when you adopt Game Center, this helps your game sales and makes the experience better for users and really helps promote your games. So let's go through the tabs of Game Center. And we'll start with the first tab. This is usually where people are going to first come to. It's the Me tab. It shows everything about the current player.

It's a basic player overview, and we can see, you know, the number of games I've played, the number of points I've earned from achievements, the number of friends I have. Then, you know, users get to interact, and they can share some information with a friend, so they can set a status.

And new for iOS 5, we can have photos associated with the Game Center accounts, which are visible in leaderboards in your games, and you can actually access them with an API to show and associate with their avatar in your game. And finally, the boring part, basic account management on the Game Center app. The next tab over is the friends tab. This is where users can browse and now in iOS 5 discover many new friends.

Now, this is basically the friends list. We order it by recently played. We have a few other features to order it. And we also now have a new feature called the Achievement Leaderboard. And this is where the user can come in and see how they are doing compared to their friends with all their achievement points.

And they can also compare themselves, as you can see a little hint of at the bottom, with top players in the Game Center community. We really think that this is going to drive competition and make users look for games they can purchase and play and earn more achievements so that they can climb these leaderboards and move to the top.

And new in iOS 5, we have a new feature called

[Transcript missing]

and also new in iOS 5 to aid in friend discovery, we have friends of friends. So you can find the friends that you're missing that your friends have. And we can make new friends and just always find new friends and have someone to play games with at any time. The third tab, I find this one pretty fun because I've got a lot of games on my device, is the Games tab. This is where users browse their games and where users are going to discover your games.

[Transcript missing]

at the Game Kit framework overview. Game Kit is a framework to enhance game development. We want to provide you access to all the social features that Game Center provides and provide you incentives or provide you functionality, provide incentives to your users to keep playing your game.

So we provide the basic authentication that gets things started and gets the ball rolling and then APIs to submit scores when your user makes a high score and show it in the leaderboard and then reward the user for beating a game level or killing the final boss with achievements.

And finally, we provide APIs to establish multiplayer games, and you can connect the people with our API, auto matching our invites, and then play either a peer-to-peer game, a server hosted game where you host the game on your own servers, or a new, a turn-based game.

[Transcript missing]

Players are all the people in Game Center. We have 50 million of them. Each player is backed by an Apple ID.

So everybody has an Apple ID. Every player has an invariant player ID that you can use to identify this player in your code and in your save game files and when you communicate with the Game Kit API. Also, to enhance the experience and to draw your users into your game better, you can take advantage of some of the settings that the player has in Game Center, such as their nickname and their photo. We encourage you to use the nickname that you get from Game Center when a user signs in, you know, when you're walking them through, instead of having to enter a new profile name.

And also, in iOS 5, if you load the photo, you can really, you know, personalize the game experience for them. Show on the right here in the block diagram a couple of the properties that GKPlayer has. As I mentioned, it has a player ID and a nickname and photo.

One of the players you can use all the time is the local player. The local player is special. It's a subclass of GKPlayer. It's a GKPlayer called GKLocalPlayer. It provides additional functionality, such as access to the friends list, so you can see the friends of this player and explore the friend graph.

It also provides you a flag to indicate if this player is underage. When they signed up with Game Center, we find out this information and we'll convey it to you in case you need to use this information for locale-specific reasons. And most importantly, the GKLocalPlayer class provides the authentication API.

This is how you are going to initialize your game with Game Center. Let us know that the local player is authenticated. And if necessary, Game Center is going to do the work to gather the information and authenticate the user. And as you can see from the block diagram, local player has basically the same properties as player, plus the additional ones I've already mentioned, the friend list, the underage property, and whether the player is authenticated. So let's take a quick look at how authentication works and what's going on. All Game Center games start by authenticating. educating the local player.

We want you to do this as soon as possible. We recommend you do it when you're basically apt to finish launching. Game Center handles the process of authenticating the player automatically. So the common case is the user's already signed on. We have single sign on for Game Center. So nothing else needs to happen.

We're going to show the banner welcoming them back to your game. And game will continue. You should continue and move on. However, if this is a new user to Game Center or they've signed out, we're going to handle first time sign on. So the authenticate call is going to process, allow the user to use an existing account or create a new account. And then we will call your completion handler when it's all done.

And finally, we also handle the tricky case if a user doesn't want to use Game Center right now. We handle this case where they choose to opt out. So if the user chooses to cancel from this alert three times in a row, we will let the user opt out of Game Center and we handle this automatically and we communicate this to you with an error code.

If this happens, the user can re-enable Game Center simply by going to the Game Center app and signing in. So let's take a look at the steps we recommend for authentication. Because Game Center shipped with 4.1 and doesn't support all devices, you need to check a couple things first.

One, you want to check for the presence of the Game Center API. You need to test the OS version to make sure it's greater than or equal to 4.1. And then you're going to request authentication. If both of those cases are true, using the GK local player API.

The end, check the result and do the appropriate steps for your application to enable or disable Game Center functionality. It's important, though, that if the user can't authenticate for some reason, that your games still work, that there should be something they can play. Otherwise, they're going to be fairly disappointed.

So let's take a look at this in code. First thing we do is start at the top. We're going to get the class from this local player using NSClass from string. Then we're going to test the version number to make sure that it's greater than or equal to 4.1.

If supported, which we check here, we have a class, and we have the right OS version, we're going to authenticate using authenticate with completion handler. Here the completion handler can receive an error, but it's important to note that I don't use the error to determine if the player is authenticated.

We check the local player's authenticated property because you may receive an error that the user is offline but still have an authenticated game center player, in which case proceed with game center. We function in an offline mode so that users can keep playing their games. So as you saw, there's some errors that you might get, and authentication may not succeed for a couple reasons. First one.

You might get is Game Center is not enabled. This is the GK error game unrecognized. This can happen if you missed a step when submitting your app to the app store and forgot to enable Game Center for this version. So I'll show you what to look for a little bit later so you never get this error code.

is GK error not supported? This is if the device is not supported. There are some old devices that Game Center is not supported on. We handle this for you and we'll return you this error on authentication and the local player will not be authenticated. If the user has canceled authentication, chose not to use it this time, or opted out, we will give you the GK error canceled error code, in which case you should proceed with your game with Game Center features disabled.

It's very important to provide a graceful fallback. If the user is offline, they may be authenticated, still want to play, but if they're not able to authenticate for some reason, proceed with your Game Center features disabled and do not show Game Center UI. And if the user submits scores, you may want to save those in your save game file for when the user authenticates in the future. That is up to you.

So leaderboards are a great feature that Game Center provides to enhance competition. By showing someone where they rank amongst their friends and amongst the best player in the world, you're really going to tweak their competitive nerve and they're going to want to, you know, play your game more so they can do better and progress up the leaderboards.

So the Game Center leaderboards allow players to track how their friends are doing and see how the best players in the community are doing. These encourage return play. You know, got to come back. My friend just beat my high score. They're ahead of me in the leaderboard. That irks me, so I'm going to come back and I'm going to play your game more so that I can beat them.

We try to beat our friends and we come back and we want to do better next time. We'll try to beat our best score. Leaderboards are defined in iTunes Connect. It's important to specify all these parameters. And I'm going to go over them real quick because there are a couple of gotchas here. The first thing you do is you give the leaderboard a name.

This is how you refer to it. So scoreboard here. You give it an identifier. This is how you refer to it to Game Kit. We talked about leaderboards by their identifier. Then you're going to want to define a score type, whether you're using floats or integers. And then a sort order.

Most common is high to low. This is if you want the highest score to be the best score. Or you can choose low to high if you want the lowest score to be the best score. This is often a mistake and we wanted to call that out. Then you're going to define some localized properties. For the English language, I'm going to give this leaderboard a display name of top scores.

Set the score format to 100,000 with a comma as a thousand separator. And define singular and plural suffixes for the score values. These suffixes are used when Game Center displays your scores. And it's important to note that depending on your score type and your suffix, you may want to or need to prefix your suffix with a space.

It reads a lot better to say 100,000 space points than having those two round right together. But if you're talking in an abbreviation like seconds or milliseconds where you use s or ms, it makes sense to concatenate them and not have them. We give you this control, but it's often overlooked.

So pay attention. So leaderboards are interacted with a couple classes. The primary class, the thing you can probably use first is the GK score class. GK score represents the score that a player earned. And it also is used to report the high score to Game Center and the GameKit services.

We will store and forward score submissions if the user is offline. The way this will work is instead of giving you back the offline error, we're going to process that and store the score and forward it next time the user is online. You also get scores back when you query leaderboards. And in that case, the score has several properties.

The first property is the player ID. This is the player ID who achieved the score. If you're reporting the score, it's the local player. The category ID is the leaderboard that the score was earned on. Then we have the raw value, which is a 64-bit integer value that you submit with your score. It's interpreted based on the score type, the value type that you've specified in iTunes Connect. And the formatted value that we get back once we've processed your score and formatted it with your suffix.

And finally we have the rank that the score is currently at on the leaderboard, and the date that the score was achieved. Now to get these scores, you use a GK leaderboard class. There are multiple leaderboards for a game. We can actually support up to 25 leaderboards per game. They're identified as categories using the leaderboard ID. And you can get leaderboards either for a range of scores, or for scores for an array of specific players.

It's very useful if you want to show, in a multiplayer game, the ranks and scores, best scores for the four people that I'm playing with, myself and three others, so we can see, oh yeah, you can even use these potentially to make teams that are balanced. And new in iOS 5, we allow you to specify a default leaderboard. This is basically a hint to Game Center about which leaderboard we should show in the Game Center app when the user visits your page. We recommend that this probably be the score that the user last submitted.

It's an opt-in with a simple Boolean when you submit a score. Now, when working with GK Leaderboard, you're going to want to define a leaderboard with a category ID, and if you're going to query a range of scores, you'll specify the range, and then refine the query with a time scope and a player scope.

Time scopes can be today, this week, all time, and player scopes can be just friends or all players. When it returns, you're going to get back a localized title for that leaderboard so you can display it. You'll also get back the maximum range, which is the number of scores that we have in this leaderboard, and you're going to get back an array of scores matching your query.

Game Center provides a standard UI for leaderboards. This is through the GK Leaderboard view controller. And new in iOS 5, in this standard UI and in our other standard UIs, we provide access to app store ratings. So users who love your game can rate it right from the leaderboard.

It's great if they just got their best score, they're going to be very happy, and hopefully they'll give you five stars. Our leaderboard implementation, implementation, provides both the friend and global leaderboards in one view. So they can scroll, see their friends, and scroll further and see the best players. However, you can implement custom UI yourself, pulling data with the GK Leaderboard class, and displaying it in a table view or some other form. One thing that's worth mentioning for performance reasons, it's recommended that you load small ranges.

There is actually a limit to how many scores you can load at once of 100. Our implementation tends to be a little bit more complex. It tends to be around 25. And then we just feel that it gives a better performance for the user. You know, load small ranges, they come back quicker. We prefetch the next page. So how to submit a score? First thing you need to do is initialize a score with a category. Here, I'm kind of boring, I got a leaderboard category. Then we're going to set the value.

It's my new high score. And you'll see this next property. This is context. This is new in iOS 5. This allows you to specify 64 bits of your own data attached to the score. Game Center doesn't interpret it. Game Center doesn't process it. But if you wanted to use it in a custom leaderboard or to store and pull some information about this best score for your user, like the level they were on when they achieved it, what player class they were using when they achieved it, you can store some data in here and pull it out. Also, I'm using a new API in iOS 5, the default leaderboard.

So I want to make this score my default leaderboard. Once I've configured the score, we report it with report score with completion handler. And if it fails, you'll get an error. Before iOS 5, you might have gotten communication errors, and we recommended that you store these scores and forward them when the user is next available. With iOS 5, we do that for you now.

And in those cases, you won't get errors. How to load scores so you can display your leaderboard or just query the scores for a bunch of players. We initialize a leaderboard, and then we set up the query. We're going to set the category for the leaderboard here, and we're going to set the range.

Leaderboards are one indexed. Zero is not a valid rank, so always start your range with one. And I'm going to load 10 scores starting from one, so the top 10. Going to configure the time scope and the player scope here. I want all time scores for my friends.

And then I'm simply going to load the scores using load scores with completion handler. This completion handler has two properties. It comes back with scores, which are the scores that were loaded, and possibly an error. And you'll notice in my handling code, I handled them separately. We might get scores at the same time we get an error.

This can happen if the user is offline, so we couldn't load new scores, but we have cached scores. It's better that we give you something so that you can display the best information that Game Center has available. So that wrapped up leaderboards, and let's move on to achievements. As you can see, achievement view controller, we can rate games right here. Achievements keep players involved.

You know, if you have achievements and you display them to the user, they can see the achievements list in Game Center, and they're going to be inquisitive and figure out how to unlock these achievements. And if you provide hidden achievements, you know, there are little hints. We'll indicate that there are ten achievements, but there's only nine in the list.

The user might get the subtle hint that there's one missing, and they're going to look for it. If they see that their friend found the hidden achievement, which we won't reveal what it was exactly, they're going to talk to their friend, and they're going to ask how they got this achievement. And so that, you know, we allow them to compare to their friends, and they can get more hints about your hidden achievements.

Achievements are a great way to track game progress and to reward exceptional results. They really encourage return play. I know quite a few people that won't put down a game until they've unlocked all the achievements. Or at least all the achievements they think they can get. Achievements are defined in iTunes Connect like the leaderboard.

Here you're going to define before and after achieved states. You'll be able to define achievements as hidden if you want them to be hidden from the user until they've earned them. And you can also define the images. These are images that we will display in Game Center after applying to a gold coin template.

There's a single set of achievements per application. You get 1,000 points total for your achievements. You can have up to 100 achievements. And you can have 100 points per achievement. We certainly recommend that, you know, common sense would prevail, you know, give points based on the difficulty of the achievements, the value of the achievement.

You know, with the achievement leaderboards, points on achievements matter now. So users are going to come back to your game and they're going to strive to get these high valued achievements. And hopefully this keeps them coming back until they do. And you add new features and you add new achievements, you can get them to come back again. So there are primarily two classes when you're talking about achievements in Game Center.

The first of which is the GK achievement description. This is the definition of the achievement. This represents what you put into iTunes. This is what you put into iTunes Connect. You can use the achievement description class to load all the descriptions for your game. And you can use the achievement description class to load the achievement image.

Each achievement description has a handful of properties. There's the achievement ID. This is the identifier that you gave the achievement in iTunes Connect. A localized title. Obviously the title of the achievement. And there are two descriptions. There's the achieved description and the unachieved description. They'll see the unachieved description until they've gotten 100% complete on the achievement. In which case we'll show the achieved one.

You also mark the achievement as hidden. And it will be hidden until they've gotten progress on it. And you can get the image for them, the achievement description. The GK achievement class is the user's achievement. This is what the user's actually earned and what they've gotten. And it tracks their state. You use the GK achievement class to load the achievements that the player has earned. So this is going to return to you an array of achievements that's of a differing length. From your achievement descriptions.

It's what the user's actually done. And new in iOS 5, when you submit an achievement, we give you the option to show a banner to the user that they've completed the achievement. If the achievement's got 100% complete and you choose to show the banner, we will show a banner. It looks a lot like the welcome banner with the title and the description of the achievement. The GK achievement starts with an achievement ID.

This is the same one. It matches up with the achievement descriptions. And then you specify the percent complete. This is the user's achievement. This is the user's progress. And we support partially complete achievements. You can then query an achievement description for whether it's completed or whether it's hidden. And you can get the date that the achievement was last reported.

And new in iOS 5, you choose to show the banner when you submit the achievement. To display the achievements to the user, we provide standard UI. This is the GK achievement view controller. Game Center standard UI shows the list of achievements, a summary of what the user has and has not earned, and provides app store ratings.

So let's take a look at some code to submit an achievement. Starts off by initializing an achievement with an identifier. Since I've completed this achievement, I've got it 100% complete. And I want to reward the user with immediate feedback with the banner. And then we'll report the achievement to Game Center services with report achievement with completion handler. Just like with scores, Game Center and iOS 5 will store and forward the achievements if we were not able to send them to our servers.

However, if you are running on a server, you can also report the achievement to the GK. If you are running on a version prior to iOS 5, we recommend that you consider storing and forwarding these yourselves, especially if you already have code to do so. Otherwise, you just need to handle the error. So one of the big features in Game Center that really keeps people involved and interacting with each other, which is the reason we have friend graphs, is to play multiplayer.

Users want to come together and play together. And Game Center offers two modes of live multiplayer, either peer-to-peer or hosted. Peer-to-peer is where we have the devices communicating directly to each other. And hosted is where we allow the devices to communicate to your server. In either case, multiplayer's connections are established through either invitations or through auto-matching. Auto-matching is a service that Game Center provides where we will pick the best people from a pool of people that are wanting to play the game at the same time.

And there are various properties we use to match people. And we allow you to customize some of the properties through player groups and player attributes. But in the end, the end result is that we get people together through these two methods so that they can play a game and keep coming back.

If you're playing a peer-to-peer game, you can take advantage of the in-game voice chat feature. And new, we have turn-based multiplayer. It's a new way to do multiplayer. People don't have to all be online at the same time. But we put people together the same way. And the UI is very similar.

We allow people to hook up for turn-based through invitations and auto-matching. So why add multiplayer? It's quite a bit of work. You usually want to think about multiplayer from the beginning. But it almost always pays off. It really makes your app stand out. If you think about some of the most storied franchises in gaming, the ones that have had the longest run, the most longevity, some of the more legendary franchises had great multiplayer.

And they continue to live beyond the single-player campaign because of the communities that play their multiplayer. People really like to play against real opponents. We're really good at figuring out the inadequacies of AIs and bots. We can figure out how these scripted opponents do things and they get too easy to beat. Also, multiplayer will encourage cooperative play. There are a lot of communications in the forums. People talk about and really request multiplayer.

And so it's one of the most discussed and requested features around. And one of the features that I like to see is cooperative play. It's fun to play with someone instead of against them for a change. So imagine it really works. It really can increase the longevity of your game. One of the ways this can happen, especially with the friend graph in Game Center, I've played your game. I've had a lot of fun. I beat the single-player campaign. And I've got all the achievements and I put it down.

But my friend in Game Center discovers this game off my friend list, starts playing it, and sends me a game invite. That's going to get me back in the game and hopefully other players as well and will keep coming back and playing your game now that I can play it with my friend.

It's a great way to -- to keep people coming back to your game and hopefully get more people playing it. It's sort of viral. You know, the invitation message that we send, if the user receives the invite and they don't have the game installed, we will still show them the invite and give them the option to buy the game at that time and continue and play with their friends. Let's take a look at how the invite flow works. We start with the device on the right. I want to play a game with my friend.

So first thing I'm going to do is I'm going to invite my friends from my friend list. I invite Eunice to play. And we're going to send the invite. The invite results in a push notification. Here I'm showing the new banner from Notification Center. If I want to play -- if my friend wants to play, she'll tap the banner, which will bring her into your game, into the matchmaker controller, send a reply back, and we're both ready to play.

All I have to do now is hit play now and jump right into the game. This is some screenshots from our demo game you'll be seeing in tomorrow's sessions. We did a little take on Rock, Paper, Scissors. And the rest of my team will be happy to show it off. So GameKit provides several ways to get connected. And the first one we'll look at is peer-to-peer.

Hosted is very similar. You start with the GK match request. The match request defines the parameters of the match. And if we look at the block diagram, we can see that for each match request, we want to specify a minimum and maximum number of players. If you use a standard UI, this allows the user to change the number of players in the game and allows them to select.

If you go with programmatic options, you can change the number of players in the game and allows them to select. If you go with programmatic auto-matching, it gives some flexibility in who we match with you and we can get more flexibility and find games quicker. You also can specify a player group if you want to keep matches separate.

This is great, for example, if you're playing a racing game that has different tracks and users want to play on a specific track. You put them in a player group for that track. Similarly, player attributes kind of tell us what players from within a group should be put together. And this is done through a Boolean option.

And we'll get more details on this in a later session. And finally, another way that you can set up the match request, you can add players to invite to this. If you specify an array of players to invite, this will bring up the matchmaker view controller with these people preselected for the user to invite to the game.

This is what you're going to want to do when you receive players to invite from Game Center if the user chooses to play a game directly from the Game Center app with one of their friends. Once you've passed the match request off to one of the mechanisms to find you the match, either the Match Review Controller or the Matchmaker, you get back a GK match.

The GK Match manages networking in a peer-to-peer match. We also use it to track player state, so you can find out when players disconnect and initially connect. The GK Match provides to you an array of players. It also provides you the expected player count, because at the time we hand you the match, it's immediately after matchmaking is completed. We know there are going to be players coming in, but we don't necessarily know exactly who. So you'll wait for people to connect, and once all players are connected, you're ready to start the game.

GK Match provides you mechanisms to send data to players. You can send them to individual players or to all players. And you can track player state changes in case someone takes a phone call and disconnects. You can handle that state, report it to the user. Sometimes it's possible to even come back. And new with iOS 5, we'll talk about it a little bit later, is a reconnect feature. So in a two-person match, you can reconnect with the player. And continue your game.

The GK Matchmaker is a singleton object in GameKit framework. You're going to set your invite handler on the matchmaker. This is a block that you use to handle game invites. So when the user accepts a game invite, we call your block and provide you the invite, which you then feed to the UI to start the game. You can also use the GK Matchmaker to provide quick auto-matching without showing the standard Game Center UI. And the fourth piece is the Matchmaker View Controller.

This is Game Center's standard UI for matchmaking. It handles invites and auto-matching. And also provides another mechanism for you to get great apps for ratings. Once you have a GK Match for a peer-to-peer match, you can use GK Voice Chat to let these people talk to each other. It allows you to create a voice chat from a GK match. You can have multiple named voice chats.

Users can control their participation in the chats, so they can leave a chat, enter a chat, and mute a chat. They can also get player state updates for when players enter or leave a chat and adjust the volume on a chat. You do this through a GKE voice chat object, which you create from a match with a name. Obviously it has the players that are participating in the voice chat. It has their states, which you can query and be updated with. And then you can query and set whether the voice chat is the active chat, this is the chat that the microphone is routed to.

And you can also adjust the volume of the chat to squelch other chats if you have multiples going on at the same time. The big feature for iOS 5 for Game Center is turn-based multiplayer gaming. I like to think of this as a more leisurely form of multiplayer.

I can pick it up and I can play with my friends whenever I have time. And then when I'm done with my turn, they can pick it up on their schedule and take their turns. Yeah, games take a little bit longer, but we can keep them going for a very long time and have a lot of fun. Yeah, games take a little bit longer, but we can keep them going for a very long time and have a lot of fun. It's great for many of the classic games that you know and board games. Some examples here are the classic chess, backgammon, checkers.

But you can think of many others that this might be very applicable to. It's fully asynchronous. One way I like to think about this is saying it's always your turn. When you create a new game, it's your turn. When you enter into someone else's game, it's your turn.

Players never need to wait in the game for someone else to join, to connect. The matchmaking and the invitations are fully asynchronous. So we just tell our service, you know, I want to invite these people and I want to auto match for this other seat. And when it's that person's turn, they'll be notified that there's a game waiting for them to play. And the matchmaking seat will be filled when it needs to be filled.

You don't have to wait for someone to decide to play this game right now before you can even start. And for turn-based gaming, the game state is stored on the Game Center servers. So there's a few classes. Some are very similar. GK match request we reuse for turn-based gaming. You set it up the same way as you would for a peer-to-peer or a hosted match.

You're going to get back, instead of a GK match, a GK turn-based match. The turn-based match, like the match, tracks the state of the match, and it also provides APIs for you to load existing matches. We can have multiple turn-based matches going on at the same time, so we allow you to query them and you can show them in your own UI.

And you can also use the GK turn-based match to do quick auto-matching without any UI. The GK turn-based match object provides you the match identifier, the creation date of the match, the array of participants. So these are a little bit more than players, and I'll show you later in a second.

We get the status for the match, whether it's active or not, or finished. You can query and download the match data for the match. So this is actually your game state that you associate with the match. And you can set a custom message that will display in the Game Center UI after each and every turn.

To display the list of matches and to create new matches, you can use the GK turn-based matchmaker view controller. This is, again, Game Center's standard UI. It provides a list of the matches that are ongoing for this player, and we separate it by where it's my turn, someone else's turns, or games that I finished that I might want to browse later.

It also provides connection between players via the standard mechanisms of invitations and auto matching. There are a few more classes for turn-based match. There's a little bit more to deal with here. Since there are additional events beyond just getting an invite, we have this GK turn-based event handler. This is a singleton object that you will use and set a delegate on, and it routes events to your delegate.

These events include things like new game invitations or new turns when it's your turn and the case where a game is over. And like I showed you, as you saw on the GK turn-based match, instead of an array of players, there's an array of participants. Participants are a little bit more than players. They represent a seat at the table, and they actually could be empty initially if you're waiting for someone to take it.

Each participant tracks the state of that current participant, the player state there, and will also be used to represent the outcome of the match. At the end of every turn-based match, you need to set the outcomes for all the participants so that Game Center and your UI, if you want, can know who won, who lost, if it was a tie, first, second, or third place. And we also allow you to specify some custom parameters to the outcome.

Each turn-based participant has a few properties. There's a player, if a player has been assigned to the seat. There's also the date of the last turn taken by this participant, the status of this participant, whether they're actively playing, whether they've quit, or whether we're still waiting for someone to be matched, and finally, the in-game outcome that you can set for each participant. Taking a turn on a turn-based match is pretty straightforward.

First thing here I'm doing, I'm getting my current match. This is whatever the user is playing. I'm going to get the game state for that match as game data here. And I'm going to figure out who should be the next participant. The next participant can be anybody in the match. It doesn't have to go sequentially. You can reverse it. You can skip. You can totally change who it is. It can be anybody in the match. It can even be the same player again.

Then at the end, we'll intern with next participant, providing the match data and a completion handler on the result. This will send the match data and communicate who the next participant in the match should be. Then the services will send a notification to the next player so they can take their turn.

So, that wraps up a overall view of the GameKit framework and what APIs provides. We have several sessions coming tomorrow with more in-depth at various topics in there. But before I leave you, let's talk a little bit about the GameCenter services and how you can set up your app, test your app, and submit it to the store.

This is the third piece that Game Center delivers. And you communicate your data to the Game Center services through iTunes Connect. The first thing you need to remember to do if you want to use Game Center is to enable your game to use Game Center. That's pretty obvious. Then you want to really seriously consider adding leaderboards and achievements.

And if your game has multiplayer, you use iTunes Connect to specify multiplayer compatibility. We foresaw the need for cases where one version of an app may not be compatible multiplayer-wise with an older version of an app. Or say you add new multiplayer to version 2, it's not compatible with version 1. This allows you to control that. Here's what the iTunes Connect UI looks like. You access it through Safari or your web browser. And you're here and you haven't yet enabled Game Center for your app, so you want to click the enable button.

Your app is Game Center enabled. We can use this same screen to go on and add leaderboards and achievements, which is what I'll do next. First thing we want to do, I've got some leaderboards here, but I want to walk through adding a new one. So we'll click the "Add Leaderboard" button.

For this new leaderboard, I'm going to specify a reference name. Here, number of rock. I'm going to use this leaderboard to identify the number of times I've chosen rock in a rock, paper, scissors game. And I give it a leaderboard ID. It's an integer. And I'm going to rank it high to low so the most times someone chooses rock, they're on top.

Next, I'm going to add language. Make sure that we have a title for this leaderboard. I'm going to call it Rock. And we're going to set up a suffix. And if you look closely, I've got preceding spaces on my suffixes of Rock and Rocks. And this is an integer value.

Once we're done, we can save and add other localizations. Next, I'll look and show you how to add achievements. So similarly, we're going to click the Add New Achievement. I've got a few here already. We add a new achievement. Here is my creatively named Rock Steady achievement. I want to give this to people that choose rock multiple times in a row.

I'll give it an identifier and it's going to be hidden because I don't want to be obvious that you should choose Rock sequentially. And it's got a point value of 100 points. I mean, if you manage to win picking the same -- picking Rock many times in a row, well, I guess you deserve a lot of points.

Then we'll add some localization. We're adding a language. Title is Rocksteady. And two descriptions here. You know, what -- before they earn it, you know, tell them to choose Rock ten times in a row. Now, obviously, it's hidden so they don't see that, but it's worth putting it in there in case you want to unhide it later. And their reward for earning it, they get to see the icon of a nice purple rock and you're steady as a rock. And then we'll save this. and once we're done making all edits and adding all our achievements, we can save the achievements.

So when you're developing an app, your iTunes kinetic first goes into a sandbox. And this is the environment that we provide, so that you can develop your app before submitting it to the store and develop new versions of your app. Games and development run in the sandbox, and this includes development builds that you build and install on your device via Xcode. This includes builds that you install and run on the simulator. And it also includes ad hoc builds that you might deliver to beta testers. So beta testers playing an ad hoc build will be playing in sandbox with your test version.

Contrary to this, games in the App Store, once you've submitted it, use our production servers. But we thought about you when testing these games. We knew you'd want to test backwards compatibility, especially in multiplayer. So it is possible, and I'll show you how in a moment, to test a production game on Sandbox. So you can test your live app with your new development app and play multiplayer against each other and make sure that it works. So the way to look at Sandbox is basically as another set of services.

It's for testing your application with Game Center. It duplicates all the production Game Center functionality. Provides -- you know, you use the same iTunes connect metadata, and these are separate servers and separate players. As there are separate players, a couple things to keep in mind. You can use the same Apple ID for sandbox and production, but they will be separate GKPlayer objects.

We have a tip for identifying which environment you're in. Use a different nickname. Here, my example, I'm Apollo in production, but in Sandbox, I'm Apollo Sandbox. Switching to Sandbox is pretty straightforward. It happens automatically. So when you run your app that's in development or an ad hoc build, Game Center detects this and will automatically require the user to authenticate into Sandbox if they're in production. It only happens when required.

And it happens during authentication. Switching out of Sandbox is a manual process. As I mentioned, we wanted to allow you to test your production apps in Sandbox against your new version, so we made this manual and you have to do it yourself. You do this by logging out with the Game Center app and then logging back in or launching a live game, a production game, and logging in.

So the last thing you need to do when you submit to the app store is to make sure you enable Game Center for this version of your app. Each version of your app can have Game Center on separately. So click that gray button and make it green. Then verify that your bundle identifier and version are correct. Submit your game to the app store.

This will send your metadata to the production environment. And it's worth noting and keep in mind to test your leaderboards because changes are restricted after this. You can't remove leaderboards once you've submitted and you can't change the sort order. So high to low or low to high is permanent.

So that wraps up Game Center services. I want to give you a quick summary. A couple things to become a Game Center game. You enable iTunes Connect. You enable Game Center and iTunes Connect and you authenticate the player. That's the minimum to be recognized by Game Center and get your game to show up in the game list.

But you really need to consider adding one of our features for Game Center, including leaderboards, achievements, and multiplayer. So quick summary of some of the features new for iOS 5. We have turn-based gaming. We now have a custom invite sound that you can specify in your bundle so that instead of the trumpet, you'll hear your sound when the game -- the player receives an invite.

You can add players to in-progress peer-to-peer matches. Users can now submit app store ratings from the Game Center UI and get game recommendations and friend recommendations to discover new games and new friends. And there are the achievement leaderboards to foster competition and more features which we'll cover later in other sessions.

So wrapping up, Game Center and Game Kit provide easy ways to enhance social gameplay. We have several features to do so and encourage competition and cooperation. And Game Center, the application, provides a lot of ways for your apps and your games to get discovered if you adopt Game Center.

We show you your friends' games. We have game recommendations based on games your friends are playing. We have multiplayer invitations that will allow users to purchase the game if they don't have it yet. And on iPad, if you've seen the Me page, it has some icons for top games where we will show featured games. So there's a couple more sessions on Game Center, three more tomorrow to be exact.

Starting at 9:00 a.m. in the morning in this room, we have working with Game Center. Then we have multiplayer gaming and turn-based gaming with Game Center. And I will repeat this session on Friday for any of your colleagues that were not able to make this time slot. Thank you very much. I hope you add games Add Game Center to your games.