6

ゲームセンターを使おうとしています:マルチプレイヤー

これまで、プレイヤーは Game Center に対して認証を行っており、スコアやアチーブメントを送信/読み取りできます。マルチプレイヤー機能については、両方の方法を試しました: - Game Center インターフェイスを使用して一致を見つけます。- プログラムで一致を検索します。

どちらの方法でも、次の問題があります: マッチ デリゲートの match:player:didChangeState: メソッドが呼び出されません。Apple ドキュメントでは、1 人のプレイヤーが接続または切断された場合にこのデリゲートが呼び出されると記載されています。

私の場合、このデリゲートは呼び出されません。一歩足りないと思います。デリゲートの実装後 (apple doc で指定)。

- (void)match:(GKMatch *)match player:(NSString *)playerID didChangeState:(GKPlayerConnectionState)state
{
    switch (state)
    {
        case GKPlayerStateConnected:
            // handle a new player connection.
           break;
        case GKPlayerStateDisconnected:
            // a player just disconnected.
           break;
    }
    if (!self.matchStarted && match.expectedPlayerCount == 0)
    {
        self.matchStarted = YES;
        // handle initial match negotiation.
    }
}

また、一致を見つけるためのコード。

-(void) findProgrammaticMatch
{
  GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease];
  request.minPlayers = 2;
  request.maxPlayers = 2;

  [[GKMatchmaker sharedMatchmaker] findMatchForRequest:request
                                 withCompletionHandler:^(GKMatch *FoundMatch, NSError *error)
  {
    if (error)
    {
      // Process the error.
      StatusLabel.text = @"Match Not Found";
    }
    else if (FoundMatch != nil)
    {
      MultiPlayerMatch = FoundMatch; // Use a retaining property to retain the match.
      StatusLabel.text = @"Match Found";
      MultiPlayerMatch.delegate = self; // start!
      // Start the match.
      // Start the game using the match.
      [self StartMatch];
    }
  }];
}

ご協力いただきありがとうございます。

4

2 に答える 2

2

It was working all along. The only difference is that... when you use invites the event "didChangeState" doesn't get called. You're connected without notice and you can start to receive data. I never tried to send/receive data because I was expecting the event first, but i did send something by mistake one time, and it worked.

- (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *) match {    
    //Dismiss window
    [self dismissModalViewControllerAnimated:YES];

    //Retain match
    self.myMatch = match; 

    //Delegate
    myMatch.delegate = self;


    //Flag
    matchStarted = TRUE;

   //Other stuff
}

- (void)match:(GKMatch *)match player:(NSString *)playerID didChangeState:(GKPlayerConnectionState)state  {
    //This code gets called only on auto-match
}

The above code works as expected.

于 2011-06-16T13:47:58.473 に答える
0

didChangeState: GKPlayerStateConnected は、プレーヤーが GKPlayerStateUnknown であった後に戻ってきた場合、または進行中の試合に追加/招待された場合にのみ発生する可能性があると思います。

于 2014-12-02T09:28:20.017 に答える