2012-01-10 11 views
1

ゲームセンターアプリを持っています。私は(私は今、私は接続しないでください1つのクライアント(投票サーバ)findAdditionalPlayerを呼び出す場合そう...iPhone/IOS 5で[GKMatchmaker addPlayersToMatch]を持つプレイヤーを追加できません。

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

のような[GKMatchmaker addPlayersToMatch]と第三/第四クライアントを追加しようとしている2つのクライアントを成功裡に接続して、などのメッセージを送信することができます他のクライアントはGKMatchmakerViewControllerを使用しています)。奇妙なことに、接続されたクライアントが両方ともfindAddtionalPlayerを呼び出すと、完了ブロックは(the match.expectedPlayerCount == 2)を実行しますが、第3のクライアントは決して接続しません。

ただ1つのゲームクライアントがこの機能を呼び出すべきですか?ドキュメンテーションは実際には指定されていません。

addPlayersToMatchを使用した例はありますか?彼らはゲームに再接続(とゲームセンターを経由して、前後の通信)するために私の経験で

答えて

1

、2人用のゲームのために、addPlayersToMatchは両方のプレイヤーで実行する必要があります。

どちらもfindPlayersToMatchを呼び出しているので、両方がfindAdditionalPlayerを呼び出すと、2つのクライアントが接続できることは意味があります。

すでに2人の選手(たとえばAとB)でゲームを持っていて、参加する第三プレーヤー(C発言を)したい場合は、あなたがする必要があります:プレーヤーA(C招待)で

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]; 
:プレーヤーC(A及びBを招待する)において

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招待)で

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]; 

だから、試合に新しいプレーヤーを再度参加または追加するメカニズムがあるように思わ:

  1. プレイヤーが検出された場合、リモートプレイヤーが切断した(または完全に新しいプレーヤーが追加された)、新しい対戦要求オブジェクトを作成しますこの新しいマッチリクエストのplayersToInvite配列に切断された/新しいプレイヤーのIDのみを含め、addPlayersToMatchをそれと共に実行します。切断プレイヤーは、その対戦要求のplayersToInvite配列に(あなたがGKMatchのplayerIDsプロパティからそれらを事前に配列に格納または取得する必要があります)すべてのリモートプレイヤーのIDを含め、新たな対戦要求オブジェクトを作成再開
  2. addPlayersToMatchを実行します。

つまり、既存のプレイヤーのそれぞれはマッチオブジェクトに新しいプレーヤーを追加し、新しいプレーヤーは既存のプレイヤーをマッチオブジェクトに多く追加します。 4人用のゲーム(プレーヤーA、B、C及びプレイヤDが最新追加されD)について

: プレーヤーA、B及びCは、それぞれ、そのplayerToInviteのみD'Sから成る対戦要求オブジェクトとそのaddPlayersToMatch呼び出しを実行playerIDプレーヤーDは、playerToInvite配列にA、B、およびCのplayerIDが含まれている一致要求オブジェクトを使用してaddPlayersToMatch呼び出しを実行します。

+0

私は4人のプレーヤーが遊んでいる問題を抱えています.1人のプレーヤーが切断されたら、他の3人もまた切断されます。それは起こります。 –

関連する問題