簡體   English   中英

GKTurnBasedMatch退出

[英]GKTurnBasedMatch quitting out of turn

當用戶使用GameKit在iOS應用程序中基於回合制匹配“輪流”退出時,委托方法-(void)turnBasedMatchmakerViewController: (GKTurnBasedMatchmakerViewController *)viewController playerQuitForMatch:(GKTurnBasedMatch *)match; 在GKTurnBasedMatchmakerViewController上調用,根據文檔,我們應該為當前玩家設置結果,並調用participantQuitInTurnWithOutcome:nextParticipant:matchData:completionHandler

但是,我無法找到關於球員退出的任何信息。 那是在輪到我的時候,我退出了媒人視圖控制器。 似乎沒有任何委托方法,並且令人驚訝的是,通過調試我的應用程序,我發現轉彎被發送(即使它現在不在我的回合中)。

任何人都可以解釋行為和正確的方法來處理退出退出。

您可以在中處理此方案

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

您可以檢查匹配中的當前參與者,看看是否是您。 至於發送的流量,游戲中心是否需要通知所有其他玩家您已退出?

實際上有一種方法可以退出:

對於GKTurnBasedMatch,它被稱為:

participantQuitOutOfTurnWithOutcome:withCompletionHandler:

當調用turnBasedMatchmakerViewController:playerQuitForMatch:函數時,可以在GKTurnBaseMatchMakerViewControllerDelegate中調用它。

請在此處查看官方文檔

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM