我試圖使用遊戲中心後稱爲:多玩家遊戲中心:匹配委託的未找到匹配
截至目前,玩家要進行身份驗證遊戲中心,它們可以發送/讀取的分數,並acheivements。 對於多人遊戲功能,我嘗試了兩種方法: - 使用遊戲中心界面來查找比賽。 - 以編程方式查找匹配項。
對於這兩種方式,我有以下問題:匹配委託的匹配:player:didChangeState:方法不被調用。 在蘋果文檔中,聲明如果一個玩家連接或斷開連接,則會調用此代理。
在我的情況下,這個委託永遠不會被調用。我認爲我錯過了一步。 這裏是在執行我的委託之後(如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];
}
}];
}
感謝您的幫助。
我不相信這是真的。我剛剛測試過自動匹配,didChangeState從不會觸發。只有didFindMatch。我認爲didChangeState可能只有在玩家進入GKPlayerStateUnknown然後回來,或者他們被添加到進行中的比賽時纔會發生。 – 2014-12-02 09:23:51