Domanda

I am working on a multiplayer game and my match is started successfully. I have 3 players in my case. Player1, Player2, Player3. from Player3, I call disconnect method of GKMatch object and my disconnect method is

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

on the Player1 and Player2 Devices this didChangeState function is called first time than after some times it is called again for the Player3 again. It is expected to be called one time only but its calling 2 times for both players

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

}

Any thing I am doing worng? what is the best practice to disconnect a match?

Also some times this is happening the didChangeState method is called but after a certain delay. While that some updates of disconnected player are required in game.

What could be the reason of delayed response?

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

Please help

thanks in advance

È stato utile?

Soluzione

I think this was a bug that was introduced in iOS 6 because we've seen it as well. Not only will we get duplicate disconnect callbacks, but sometimes we get disconnect callbacks from players who are actually still in the game and moving around just fine.

What I've done to get around this is to verify that the GKPlayer really is disconnected when I get the disconnect callback. All I do is check the global copy of the GKMatch that I keep around during the game, and see if the GKPlayer is still in there. If so, then that player didn't actually disconnect, so I can ignore the message:

NSString    *id;
for (id in gCurrentMatch.playerIDs)
{
   if ([id isEqualToString:playerID])
   {
    NSLog(@"player is NOT really disconnected!!!");
    return;     // just bail and ignore this
   }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top