iphone - 我的 GKMatch 没有玩家...?

标签 iphone ios cocos2d-iphone gamekit game-center

  • 我成功地显示了配对屏幕。
  • 我在 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/

相关文章:

ios - 将 AdMob 添加到 Firebase 项目时崩溃

ios - 正在主线程上执行长时间运行的操作。 swift

iphone - cocos2d Sprite 当前位置

objective-c - 我在 Objective C 中创建和填充 NSArray 的方式有什么问题?

iphone - 基于 uitextview 中的行数获取子字符串

iphone - 使用 NSOperationQueue 作为 View Controller 实例变量

iphone - WebView 和覆盖链接的问题

ios - iOS 设备是否允许未对齐的内存访问?

ios - CFUUID - 创建一次并在应用程序的整个生命周期中使用

iphone - 没有 cocos2D 的 xcode iphone 粒子