Game Development Reference
In-Depth Information
GKLocalPlayer* localPlayer = [GKLocalPlayer localPlayer];
if (localPlayer.authenticated)
GKMatchRequest* request = [[GKMatchRequest alloc] init];
request.minPlayers = 2;
request.maxPlayers = 4;
GameKitHelper* gkHelper = [GameKitHelper sharedGameKitHelper];
[gkHelper showMatchmakerWithRequest:request];
A GKMatchRequest instance is created, and its minPlayers and maxPlayers
properties are initialized, indicating that the match should have at least two and at most
four players. Every match must allow for two players, obviously, and you can create a
peer-to-peer match with up to four players. Peer-to-peer networking means that all
devices are connected with each other and can send and receive data to and from all
other devices. This stands in contrast to a server/client architecture, where all players
connect to a single server and send and receive only to and from this server. In peer-to-
peer networks, the amount of traffic generated grows exponentially, so most peer-to-
peer multiplayer games are strictly limited to a very low number of allowed players.
Note Game Center can connect up to 16 players, but only if you have a hosted
server application to manage all matches using client/server architecture. That
requires a huge amount of work and know-how to set up and use properly, so
I'll leave it out of this discussion and focus only on peer-to-peer networking.
The showMatchmakerWithRequest method is implemented in a strikingly simil-
ar way to the code that brings up the leaderboard and achievement views, as Listing
14-20 shows.
Listing 14-20 . Showing the Host Game Screen
-(void) showMatchmakerWithRequest:(GKMatchRequest*)request
GKMatchmakerViewController* hostVC = [[GKMatchmakerViewController alloc]←
Search Nedrilad ::

Custom Search