我的应用程序有一个多人模式,我使用以下代码来查找玩家:
[GKMatch ] GKMatchRequest *request = [[GKMatchRequest alloc] init];
request.minPlayers = 2;
request.maxPlayers = 4;
[[GKMatchmaker sharedMatchmaker] findMatchForRequest:request withCompletionHandler:^(GKMatch *match, NSError *error) {
if (error)
{
// Process the error.
NSLog(@"Error Match Process: %@", error);
}
else if (match != nil)
{
DuelModeController* duelModeController = (DuelModeController*)viewController;
[duelModeController updateSearchingMessageWith:@" Connecting Game..."];
}
}];上面的代码可以工作。问题是找到球员的速度非常慢,长达12到15秒。为了测试它,我使用了两个不同游戏中心帐号的iPhone和IPad,它们都有iOS10.2。
你会遇到这样的情况吗?你是如何解决它的?
谢谢
发布于 2017-04-28 04:09:58
修好了!我的应用程序决斗模式处理两个玩家。但是,在从Apple获取示例代码时,我复制并粘贴了最小和最大玩家数量。Min设置为2,但Max设置为4。
一旦我将最大玩家数设置为2,查找匹配需要2-3秒,而不是12 - 15秒。我的理论是,游戏中心可能一直在等待识别第三个和第四个玩家,看到它无法找到他们,它在12-15秒后返回成功。
学到的经验:在GKMatch中定义玩家数量时,只指定您想要的玩家数量,而不是更多。
斯蒂芬
https://stackoverflow.com/questions/43097079
复制相似问题