【问题标题】:GKMatch delegate function didStateChange calling Two times or delayed callGKMatch 委托函数 didStateChange 调用两次或延迟调用
【发布时间】:2014-03-19 06:06:30
【问题描述】:

我正在开发一款多人游戏,我的比赛已成功开始。在我的情况下,我有 3 名球员。播放器1,播放器2,播放器3。 从 Player3,我调用 GKMatch 对象的断开方法,我的断开方法是

-(void)disocnnectOnlineMatch {
    [self.currOnlineMatch disconnect];
    self.currOnlineMatch.delegate = nil;
    self.currOnlineMatch = nil;
}

在 Player1 和 Player2 设备上,第一次调用此 didChangeState 函数,然后在一段时间后再次为 Player3 再次调用它。预计只调用一次,但双方玩家都调用2次

- (void)match:(GKMatch *)match player:(NSString *)playerID didChangeState:(GKPlayerConnectionState)state {

}

我在做什么? 断开匹配的最佳做法是什么?

有时也会发生这种情况,但会在一定延迟后调用 didChangeState 方法。虽然在游戏中需要对断开连接的玩家进行一些更新。

延迟响应的原因是什么?

- (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *)match {
    [[UIApplication sharedApplication] setIdleTimerDisabled:YES];
    currOnlineMatch = match;
    currOnlineMatch.delegate = self;
    [PuzzleLogicManager sharedManager].onlineNextRound = 2;
    [self setupRandomNumberToSend:2.0f];
    [presentingViewController dismissViewControllerAnimated:YES completion:^() {
        //NSLog(@"dismissed");
    }];
}

请帮忙

提前致谢

【问题讨论】:

    标签: game-center gkmatchmaker


    【解决方案1】:

    我认为这是 iOS 6 中引入的一个错误,因为我们也看到了它。我们不仅会收到重复的断开连接回调,有时我们还会收到来自实际上仍在游戏中并且可以正常移动的玩家的断开连接回调。

    我为解决这个问题所做的是验证 GKPlayer 在我收到断开连接回调时是否确实断开连接。我所做的只是检查我在游戏期间保留的 GKMatch 的全局副本,并查看 GKPlayer 是否仍在其中。如果是这样,那么该播放器实际上并没有断开连接,因此我可以忽略该消息:

    NSString    *id;
    for (id in gCurrentMatch.playerIDs)
    {
       if ([id isEqualToString:playerID])
       {
        NSLog(@"player is NOT really disconnected!!!");
        return;     // just bail and ignore this
       }
    }
    

    【讨论】:

      猜你喜欢
      • 2013-07-10
      • 2019-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-27
      • 1970-01-01
      相关资源
      最近更新 更多