Game Development Reference
In-Depth Information
GKMatchMaker* matchmaker = [GKMatchMaker sharedMatchmaker];
[matchmaker findMatchForRequest:request withCompletionHandler:←
^(GKMatch* match, NSError* error)
{
[self setLastError:error];
if (match != nil)
{
[self setCurrentMatch:match];
if ([delegate respondsToSelector:@selector(onMatchFound:)])
{
[delegate onMatchFound:match];
}
}
}];
}
While Game Center is searching for a match, you should give the user visual feedback,
like an animated progress indicator, because finding a match can take several seconds
or even minutes. That's where the CCProgressTimer class comes in handy (dis-
cussed in Chapter 5 ) . You should also give your user a means to cancel the matchmak-
ing process, and if she does so, you should call the cancelMatchmakingRequest
method:
-(void) cancelMatchmakingRequest
{
[[GKMatchmaker sharedMatchmaker] cancel];
}
At this point, the match has been created, but all the players might not yet be connected
to the match. As players join the game, the match:didChangeState method of
the GKMatchDelegate protocol is called for each player connecting or disconnect-
ing. Only when the expectedPlayerCount of the match has been counted down
to 0 by the Game Kit framework should you start the match. The GKMatch object up-
dates the expectedPlayerCount property automatically, as Listing 14-22 shows.
Listing 14-22 . Waiting for All Players Before Starting the Match
 
 
Search Nedrilad ::




Custom Search