2012-08-27 67 views
6

我有一款使用遊戲中心和GKTurnbasedMatch的2人遊戲,iOS回合制遊戲。iOS遊戲工具包Turn Based Match Programatic Rematch

有沒有一種方法可以在比賽結束後以編程方式重新匹配對手?

我想給玩家一鍵訪問,開始一場新的比賽。

如果沒有一個按鈕的方法,有什麼潛在的選擇?

+1

好消息!現在,使用GKTurnBasedMatch的rematchWithCompletionHandler可以輕鬆實現iOS6。 –

回答

4

事實上,它會出現一個編程解決方案正由遊戲中心忽略。毫無疑問,這是一種痛苦。嘗試在@selector(doRematchTap)以下...或者一些等價的:

NSMutableArray *playerIds = [NSMutableArray array]; 
    GKTurnBasedParticipant *otherPlayer = /* Get the other player some way */; 
    GKTurnBasedParticipant *myParticipant = /* Get yourself a very similar way*/; 

    [playerIds addObject:myParticipant.playerID]; 
    if (otherPlayer.playerID) { 
     [playerIds addObject:otherPlayer.playerID]; 
    }// sanity check 

    GKMatchRequest *request = [[GKMatchRequest alloc] init]; 
    request.playersToInvite = playerIds; 
    request.minPlayers = 2; 
    request.maxPlayers = 2; 

    GKTurnBasedMatchmakerViewController *tbmcv = [[GKTurnBasedMatchmakerViewController alloc] initWithMatchRequest:request]; 
    tbmcv.showExistingMatches = NO; 
    tbmcv.turnBasedMatchmakerDelegate = /* Your normal delegate for the callbacks */; 

    [self presentViewController:tbmcv 
         animated:YES 
        completion:^{ 
         }]; 

必須注意showExistingMatches = NO,這將跳視圖控制器直接進入配對模式與正確的用戶預先選擇(它似乎),而不是顯示用戶的現有匹配。

+0

謝謝!訣竅是將showExistingMathes設置爲NO。這並不是我想要的(用戶仍然需要點擊「下一步」和「發送」,但它確實允許更容易的重新匹配。 –

+1

iOS6有一個新的API用於執行復賽而不需要遊戲中心界面。方法是: GKTurnBasedMatch-> rematchWithCompletionHandler –

1

我沒有完整的解決方案,但對你的想法:

每個球員都有一個唯一的玩家ID,就可以得到,如果你以後

didReceiveData:(NSData *)data fromPlayer:(NSString *)playerID

存儲它扔掉

現在,您可以以編程方式啓動新的比賽並邀請該球員。他會被問到是否需要複賽,然後你可以再次參加比賽。

我知道這不是太多的代碼或具體的建議,但也許它是足夠的信息找到GameKit Class Reference其餘的。

我想知道你是否能解決問題,告訴我你是否做到了,祝你好運!

編輯:

我已搜查在references,發現這個:

- (void) loadPlayerData: (NSArray *) identifiers 

我沒有嘗試過了自己,但你應該再這樣,讓玩家如果將他的標識符存儲在一個數組中並將其傳遞給該函數。

我希望他們帶來iOS6的遊戲中心的一些變化,你可以讓你的編程匹配自己的方式...

+0

我不認爲這是現在可能的。我知道的以編程方式提交匹配請求的方法是findMatchForRequest:withCompletionHandler。它在文檔中有以下聲明:匹配請求的playersToInvite屬性被忽略;要邀請特定的一組玩家參加比賽,您必須顯示標準的用戶界面。 –

相關問題