【问题标题】:Game Center can't find existing turn-based matchesGame Center 找不到现有的回合制比赛
【发布时间】:2013-05-08 05:27:12
【问题描述】:

我正在编写一款回合制 iPhone 游戏,但我似乎找不到自己的游戏。 我有三个帐户试图在我的游戏中进行匹配 - 一个在我的 iPhone 5 上,以及在 iPhone 模拟器中创建的两个不同的 Game Center 测试帐户,我在所有通过 Game Center 沙盒玩我的游戏之间切换。不幸的是,他们从来没有找到彼此,总是自己创造新游戏。我该如何解决它,以便他们始终找到现有的匹配(如果有可用的匹配),并且仅在没有开放游戏的情况下创建新游戏?

【问题讨论】:

  • 你测试得有多彻底?选择现有匹配项来满足您的后续请求可能需要一段时间。另外,您如何确定某事物是否是预先存在的匹配项?深入了解您的匹配代码和处理程序可能有助于澄清。

标签: iphone ios objective-c game-center


【解决方案1】:

我假设您正在使用 GKTurnBasedMatchmakerViewController 来查找匹配项并执行类似的操作:

GKMatchRequest *request = [[GKMatchRequest alloc] init];
request.minPlayers = 2;
request.maxPlayers = 2;       
GKTurnBasedMatchmakerViewController *mmvc = [[GKTurnBasedMatchmakerViewController alloc] initWithMatchRequest:request];
mmvc.turnBasedMatchmakerDelegate = self;
[self presentViewController:mmvc animated:YES completion:nil];

在您的委托方法中,您可以执行此操作来确定这是一款全新游戏还是您正在加入现有游戏:

- (void)turnBasedMatchmakerViewController:(GKTurnBasedMatchmakerViewController *)viewController didFindMatch:(GKTurnBasedMatch *)match {

    int numberOfParticipants = [match.participants count];
    // check the number of valid participant ids to find out if you need to know if this is a "new" game or not.
    ....

为了将用户与现有游戏配对,对手玩家必须通过在 GKTurnedBasedMatch 上调用此方法“完成”他们的回合:

- (void)endTurnWithNextParticipants:(NSArray *)nextParticipants turnTimeout:(NSTimeInterval)timeout matchData:(NSData*)matchData completionHandler:(void(^)(NSError *error))completionHandler;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-06
    相关资源
    最近更新 更多