2012-05-02 20 views
4

当用户在使用GameKit的iOS应用程序的基于回合的匹配中“反过来”退出时,在GKTurnBasedMatchmakerViewController上调用委托方法-(void)turnBasedMatchmakerViewController: (GKTurnBasedMatchmakerViewController *)viewController playerQuitForMatch:(GKTurnBasedMatch *)match;,根据文档,我们应该设置结果对于目前的球员,并呼吁participantQuitInTurnWithOutcome:nextParticipant:matchData:completionHandlerGKTurnBasedMatch退出

但是,我无法找到关于球员在quiting不合时宜的任何信息。那时候轮到我了,我退出媒人视图控制器。似乎没有任何委托方法,令人惊讶的是,通过调试我的应用程序,我发现这个转变已经发出(尽管目前还没有进入比赛)。

任何人都可以请解释的行为,并处理了之交退出的正确方法。

回答

0

您可以检查这是从匹配当前的参与者,看看是否是你。至于发送的流量,Game Center是否需要通知所有其他玩家您已经退出?

-1

其实是有退出了转弯的方法:

对于GKTurnBasedMatch它被称为:

participantQuitOutOfTurnWithOutcome:withCompletionHandler: 

你可以把它在你的GKTurnBaseMatchMakerViewControllerDelegate,当turnBasedMatchmakerViewController:playerQuitForMatch:函数被调用。

请参阅官方文档here

+2

turnBasedMatchmakerViewController:playerQuitForMatch:在玩家退出时不会被调用,所以这是行不通的。 – brimat

2

您可以通过参加

-(void)handleTurnEventForMatch:(GKTurnBasedMatch *)match 

循环处理这种情况下,如果触发球员是本土选手,他的结局是“退出”,并他不是当前的参与者(在另一个地方处理--turnBasedMatchmakerViewController:playerQuitForMatch :),然后继续并退出游戏。

for (int i = 0; i < [match.participants count]; i++) 
{    
    GKTurnBasedParticipant *p = [match.participants objectAtIndex:i]; 

    if ([p.playerID isEqualToString:[GKLocalPlayer localPlayer].playerID]) 
    { 
     // Found player 

     if (p.matchOutcome == GKTurnBasedMatchOutcomeQuit) 
     { 
      // Player Quit... ignore current participants and end out of turn only for the other player 
      if (![match.currentParticipant.playerID isEqualToString:p.playerID]) 
      { 
       // not the current participant and he quit 
       [match participantQuitOutOfTurnWithOutcome:GKTurnBasedMatchOutcomeQuit withCompletionHandler:nil]; 
       break; 
      }    
     } 
    } 
}