【问题标题】:iOS Gamecenter Programmatic MatchmakingiOS Gamecenter 程序化匹配
【发布时间】:2013-04-16 02:18:53
【问题描述】:

我正在尝试使用自定义 UI(没有 GKMatchMakerViewController)实现实时多人游戏。我正在使用startBrowsingForNearbyPlayersWithReachableHandler: ^(NSString *playerID, BOOL reachable) 查找本地玩家,然后使用GKMatchmaker 单例(我已经启动)发起匹配请求。

这就是我遇到麻烦的地方。当我发送请求时,完成处理程序几乎立即触发,没有错误,并且它返回的匹配项的预期玩家计数为零。同时,对方玩家肯定没有回应这个请求。

相关代码:

- (void) findMatch
{
GKMatchRequest *request = [[GKMatchRequest alloc] init];
request.minPlayers = NUM_PLAYERS_PER_MATCH; //2
request.maxPlayers = NUM_PLAYERS_PER_MATCH; //2
if (nil != self.playersToInvite)
{
    // we always successfully get in this if-statement
    request.playersToInvite = self.playersToInvite;
    request.inviteeResponseHandler = ^(NSString *playerID, GKInviteeResponse
                                       response)
    {
        [self.delegate updateUIForPlayer: playerID accepted: (response ==
                                                              GKInviteeResponseAccepted)];
    };
}
request.inviteMessage = @"Let's Play!";

[self.matchmaker findMatchForRequest:request
    withCompletionHandler:^(GKMatch *match, NSError *error) {
        if (error) {
            // Print the error
            NSLog(@"%@", error.localizedDescription);
        }
        else if (match != nil)
        {
            self.currentMatch = match;
            self.currentMatch.delegate = self;

            // All players are connected
            if (match.expectedPlayerCount == 0)
            {
                // start match
                [self startMatch];
            }
            [self stopLookingForPlayers];
        }
    }];
}

【问题讨论】:

    标签: iphone ios objective-c game-center gkmatchmaker


    【解决方案1】:

    想通了!我需要在我的邀请处理程序中调用- (void)matchForInvite:(GKInvite *)invite completionHandler:(void (^)(GKMatch *match, NSError *error))completionHandler,以便两个玩家拥有相同的比赛数据。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-30
      • 1970-01-01
      • 2023-04-09
      相关资源
      最近更新 更多