Game Center Multiplayer使用GKMatch但似乎无法连接 [英] Game Center Multiplayer using GKMatch but seems can't be connected

查看:114
本文介绍了Game Center Multiplayer使用GKMatch但似乎无法连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是iOS游戏中心的新人。我正在尝试使用匹配来添加我的游戏的多人游戏功能并遵循文档。

Hi I'm a new bie in Game Center for iOS. I'm trying to add the multiplayer feature using matches to my game and following the documentation.

到目前为止,我达到了我的两个客户可以成功获得匹配的地步,即matchmakerViewController:调用didFindMatch回调并传递GKMatch对象。

So far I reached a point where 2 of my clients can successfully get a match, i.e. the matchmakerViewController:didFindMatch callback is called and a GKMatch object is delivered.

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

However after that I seems to be stuck there forever, because according to the documentation, I'll have to wait until all the players (2 in my case) are actually connected before starting my game. But it seems the match:player:didChangeState callback is never called to indicate a successful connection. Well, I'm sure my clients are all in the same wifi network ( or is it a must?) Could any one enlighten me on this case? Do I have to do any extra things to make the clients to connect? Thanks a lot for the help!

推荐答案

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

So I was running into this and the solution (for me) was somewhat embarrasing. I had copied and pasted a bunch of the code from the Apple docs..and they left out an obvious step. They never actually set the match's delegate!

我的代码现在是:

- (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);}

一旦我实际设置了匹配委托,就会调用这些函数。 Doh。

Once I actually set the match delegate, the functions get called. Doh.

这篇关于Game Center Multiplayer使用GKMatch但似乎无法连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆