- 我成功地显示了配对屏幕。
- 我在 iPhone 和模拟器中运行我的游戏。
- 在这两种情况下,我都使用不同的 Game Center 帐户登录。
- 我在两场比赛中都进入了配对屏幕。我按“立即播放”。两场比赛开始寻找比赛。
- 最后,两个游戏都找到匹配项并调用以下函数:
- (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *)match
{
self.myMatch = match;
NSLog(@"%d",[[self.myMatch playerIDs]count]);
}
但我的控制台返回 0。它不应该返回 2 吗?
最佳答案
GKMatchmaker 在玩家之间建立连接之前返回给你一个匹配;在此阶段,所有参与者都处于相互连接的过程中。
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.
另外,部分播放器会出现连接失败的情况(我没有测试过这种情况不知道会不会报错)
你要找的是 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.
我还怀疑 GKMatch.playerIDs
不包括播放器;也就是说,您可能会在连接后立即看到 expectedPlayerCount = 1。
我不确定 GameKit 对线程做了什么。
关于iphone - 我的 GKMatch 没有玩家...?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5527236/