gpt4 book ai didi

iphone - 使用 GKMatch 的 Game Center Multiplayer 但似乎无法连接

转载 作者:太空狗 更新时间:2023-10-30 04:00:41 24 4
gpt4 key购买 nike

大家好,我是 iOS 版 Game Center 的新手。我正在尝试将使用匹配的多人游戏功能添加到我的游戏中并遵循文档。

到目前为止,我已经达到了我的 2 个客户端可以成功匹配的程度,即调用了 matchmakerViewController:didFindMatch 回调并传递了一个 GKMatch 对象。

然而在那之后我似乎永远被困在那里,因为根据文档,我必须等到所有玩家(在我的例子中是 2 个)真正连接后才能开始我的游戏。但似乎从未调用 match:player:didChangeState 回调来指示连接成功。好吧,我确定我的客户都在同一个 wifi 网络中(或者这是必须的吗?)任何人都可以在这种情况下启发我吗?我是否必须做任何额外的事情才能让客户连接?非常感谢您的帮助!

最佳答案

所以我遇到了这个问题,解决方案(对我来说)有点尴尬。我从 Apple 文档中复制并粘贴了一堆代码……他们遗漏了一个明显的步骤。他们从未真正设置比赛的代表!

我现在的代码是:

- (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *)match {
[self dismissModalViewControllerAnimated:YES];
self.myMatch = match; // Use a retaining property to retain the match.
self.myMatch.delegate = self; // THIS LINE WAS MISSING IN THE APPLE DOCS. DOH.
// Start the game using the match.
NSLog(@"Match started! Expected Player Count:%d %@",match.expectedPlayerCount, match.playerIDs);}

一旦我真正设置了匹配委托(delegate),函数就会被调用。呵呵。

关于iphone - 使用 GKMatch 的 Game Center Multiplayer 但似乎无法连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4337481/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com