如何识别多人游戏是由自动匹配启动的

时间:2012-12-11 10:56:31

标签: iphone ios ipad game-center

如何确定多人游戏是通过自动匹配还是邀请朋友来启动的?

我在比赛开始时调用了这个方法:

- (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *)theMatch {

    [presentingViewController dismissModalViewControllerAnimated:YES];
    self.match = theMatch;
    match.delegate = self;
    if (!matchStarted && match.expectedPlayerCount == 0) {
        NSLog(@"Ready to start match!");
        [self lookupPlayers];
    }
}

基本上我想要这个(请查看此链接) - how to sync data in multiplayer game(game-center ios)

1 个答案:

答案 0 :(得分:2)

我检查本地玩家的playerID是否包含在比赛的参赛者名单中。我发现如果他们被邀请或自动匹配,他们就不会被列出。我相信这是因为他们还没有接受比赛。

+ (BOOL) isLocalPlayerActiveParticipantInMatch:(GKTurnBasedMatch *)aMatch
{
    for (GKTurnBasedParticipant *participant in aMatch.participants)
    {
        if ([participant.playerID isEqualToString:[GKLocalPlayer localPlayer].playerID])
            return YES;
    }

    return NO;
}

如果付款人决定参加比赛,我会将其称为比赛:

GKTurnBasedMatch acceptInviteWithCompletionHandler

如果他们拒绝,我称之为匹配:

GKTurnBasedMatch declineInviteWithCompletionHandler