无法在iPhone / IOS 5上使用[GKMatchmaker addPlayersToMatch]添加其他播放器 [英] Can't add additional players with [GKMatchmaker addPlayersToMatch] on iPhone/IOS 5

查看:73
本文介绍了无法在iPhone / IOS 5上使用[GKMatchmaker addPlayersToMatch]添加其他播放器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Game Center应用程序。我成功连接了两个客户端,并且可以发送消息等。我现在尝试使用 [GKMatchmaker addPlayersToMatch] 添加第3/4个客户端,就像这样...

I have a Game Center app. I successfully connect two clients and can send messages etc. I am now trying to add a 3rd/4th client with [GKMatchmaker addPlayersToMatch] like so...

- (void) findAdditionalPlayer
{
    GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease];
    request.minPlayers = 2;  // minPlayers = 3 doesn't work either
    request.maxPlayers = 4;

    [[GKMatchmaker sharedMatchmaker] addPlayersToMatch:match matchRequest:request completionHandler:^(NSError *error)
    {
        if (error)
        {
            // Process the error.
            NSLog(@"Could not find additional player - %@", [error localizedDescription]);
        }
        else
        {
            NSLog(@"Find additional player expecting = %d", match.expectedPlayerCount);
        }
    }];
}

如果一个客户端(投票服务器)呼叫 findAdditionalPlayer 我从不连接(另一个客户端正在使用 GKMatchmakerViewController )。奇怪的是,如果两个连接的客户端都调用 findAddtionalPlayer ,那么我的完成代码块将执行(match.expectedPlayerCount == 2) ,但我的第3个客户端永远不会连接。

If one client (the voted server) calls findAdditionalPlayer I never connect (the other client is using GKMatchmakerViewController). Oddly, if both the connected clients call findAddtionalPlayer, then my completion block executes (the match.expectedPlayerCount == 2), but my 3rd client never connects.

是否只有一个游戏客户端在上面调用此功能?该文档并没有真正指定。

Should just one game client call this function above? The documentation doesn't really specify.

有人能使用 addPlayersToMatch 这个例子吗?

Does anyone have an example using addPlayersToMatch that works?

推荐答案

根据我的经验,对于2人游戏,两个玩家都应执行addPlayersToMatch,以便他们重新连接到游戏(并与他们进行交流

In my experience, for a 2 player game, addPlayersToMatch should be executed by BOTH players for them to reconnect to the game (and communicate back and forth via Game Center).

有意义的是,如果两个客户端都调用findAdditionalPlayer,因为它们都在调用addPlayersToMatch,则它们可以连接。

It makes sense that your two clients can connect if they both call findAdditionalPlayer since both are calling addPlayersToMatch.

如果您已经拥有2名玩家(例如A和B)的游戏,并且想让第三名玩家(例如C)加入,则必须:

If you already have a game with 2 players (say A and B) and you want a third player (say C) to join, you'll have to:

在玩家A中(邀请C):

In Player A (invite C):

GKMatchRequest *request = [[GKMatchRequest alloc] init];
request.minPlayers = 3;
request.maxPlayers = 4;
request.playersToInvite = [NSArray arrayWithObject:playerC_id];
[[GKMatchmaker sharedMatchmaker] addPlayersToMatch:myMatch matchRequest:request completionHandler:nil];

在玩家B中(邀请C):

In Player B (invite C):

GKMatchRequest *request = [[GKMatchRequest alloc] init];
request.minPlayers = 3;
request.maxPlayers = 4;
request.playersToInvite = [NSArray arrayWithObject:playerC_id];
[[GKMatchmaker sharedMatchmaker] addPlayersToMatch:myMatch matchRequest:request completionHandler:nil];

在玩家C中(邀请A和B):

In Player C (invite A and B):

GKMatchRequest *request = [[GKMatchRequest alloc] init];
request.minPlayers = 3;
request.maxPlayers = 4;
request.playersToInvite = [NSArray arrayWithObjects:playerA_id, playerB_id, nil];
[[GKMatchmaker sharedMatchmaker] addPlayersToMatch:myMatch matchRequest:request completionHandler:nil];

因此重新加入比赛或向比赛中添加新球员的机制似乎是:

So the mechanism to rejoin or add new players to a match seems to be:


  1. 当玩家检测到远程玩家已断开连接(或添加了一个全新的玩家)时,请创建一个新的比赛请求对象,仅包括已断开连接/新玩家的

  2. 当断开连接的播放器恢复播放时,创建一个新的匹配请求对象,包括所有远程播放器的ID(您可能必须

预先将它们存储在数组中,或从其GKMatch的playerIDs属性中获取它们在其匹配请求的playersToInvite数组中,并执行addPlayersToMatch。 >换句话说,每个现有玩家都将新玩家添加到其匹配对象中,而新玩家会将所有现有玩家添加到其匹配对象中。

In other words, each existing player much add the new player to their match objects AND the new player much add all existing players to its match object.

对于4个玩家游戏(玩家A,B,C和D,其中玩家D是最新成员):
玩A,B和C分别使用匹配请求对象执行其addPlayersToMatch调用,该对象的playerToInvite仅包含D的玩家ID。当玩家D使用匹配请求对象执行其addPlayersToMatch调用时,该对象的playerToInvite数组包含A,B和C的玩家ID。

For a 4 player game (players A, B, C and D where player D is the newest addition): Players A, B and C each execute their addPlayersToMatch call with a match request object whose playerToInvite consists of only D's playerID. While player D executes its addPlayersToMatch call with a match request object whose playerToInvite array contains A, B as well as C's playerIDs.

这篇关于无法在iPhone / IOS 5上使用[GKMatchmaker addPlayersToMatch]添加其他播放器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆