问题
- I successfully made a matchmaking screen appear.
- I run my game in my iPhone and also in the simulator.
- In both cases I log in with a different Game Center account.
- I go to the matchmaking screen in both games. I press "play now". Both games begin looking for a match.
- Finally, both games find a match and call the function below:
- (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *)match
{
self.myMatch = match;
NSLog(@"%d",[[self.myMatch playerIDs]count]);
}
But my console returns 0. Shouldn't it return 2 instead?
回答1:
Could it be that you are not actually connecting them?
Are you in fact using GKMatchmaker and GKMatchmakerViewController?
In your testing, you are sure you are using TWO DIFFERENT game center accounts?
I'm afraid I'm not familiar with the game center system.
回答2:
GKMatchmaker returns you a match before connections have been established between players; at this stage, all the players are in the process of connecting to each other.
The playerIDs property is initially set to the number of players already connected to the match; the array may be empty. Whenever a player is connected to the match, that player’s player identifier is added to the array.
Additionally, some players can fail to connect (I haven't tested this case so I don't know if you get an error returned)
What you're looking for is GKMatch.expectedPlayerCount
The value of this property is decremented whenever a player connects to the match. When its value reaches zero, all expected players are connected, and your game can begin the match.
I also suspect that GKMatch.playerIDs does not include the player; i.e. you'll probably see expectedPlayerCount = 1 immediately after connecting.
I'm not sure what GameKit does about threads.
来源:https://stackoverflow.com/questions/5527236/my-gkmatch-has-no-players