Reputation: 321
I'm creating a 2-player iOS game. I use GKMatchMaker to help me auto-match players and here's how I did when creating request:
GKMatchRequest *request = [[GKMatchRequest alloc] init];
request.minPlayers = 2;
request.maxPlayers = 2;
request.defaultNumberOfPlayers = 2 ;
request.playerAttributes = 0 ; // NO SPECIAL ATTRIBS
request.playerGroup = 0 ;
[[GKMatchmaker sharedMatchmaker] findMatchForRequest:request withCompletionHandler:^(GKMatch *match, NSError *error) {
if (!_matchStarted && match.expectedPlayerCount == 0){
...
}
}];
I set up min/max/default player all to be 2. However, every time the completion handler is called (which means a match is created), the expectedPlayerCount is always 1.
This also happens in my inviteHandler (also set min/max players to be 2 in invite request):
[GKMatchmaker sharedMatchmaker].inviteHandler = ^(GKInvite *acceptedInvite, NSArray *playersToInvite) {
if (acceptedInvite){
[[GKMatchmaker sharedMatchmaker] matchForInvite:acceptedInvite completionHandler:^(GKMatch *match, NSError *error) {
if (!_matchStarted && match.expectedPlayerCount == 0){
...
}}}];}
The expectedPlayerCount never get 0. Does anyone know how this happens? (It works fine when I'm using standard match view controller, so I suppose I set up game kit right, e.g. authenticate local player...) Thank you!
Upvotes: 1
Views: 329
Reputation: 1
playerAttributes is used in matching up players during matchmaking. GameCenter ORs different player's playerAttributes values, and if any group of players will OR to 0xFFFFFFFF, then those are the players added to a match.
Of course, playerGroup is a part of that process too, but not in this case, since all players have a playerGroup of 0 (GameCenter computes playerGroup differently.)
Try setting playerAttribues to 0xFFFFFFFF for all players
Upvotes: 0
Reputation: 31
If you do a print on the GKMatch object you will see that the GKPlayer connection state is unknown. You are seeing the expectedPlayer count of 1 because the GKPlayer has not actually connected to the GKMatch object. Within the completionHandler set the matches delegate like so: match.delegate = self. Then declare/adopt and implement the GKMatchDelegate protocol. Specifically the didChangeConnectionState. Once you set the delegate you can receive changes in the connection state of the match and be notified when players connect to the match. When players connect to the match the match's expectedPlayer count will reflect the change. Hope this helps someone.
Upvotes: 3