我正在尝试使用游戏中心:多人
到目前为止,玩家都在向游戏中心进行身份验证,他们可以发送/读取分数和成就。对于多人游戏功能,我尝试了两种方法: - 使用游戏中心界面来查找匹配项。- 以编程方式查找匹配项。
对于这两种方式,我都有以下问题:未调用匹配委托的 match:player:didChangeState: 方法。在苹果文档中,如果一个玩家连接或断开连接,就会调用这个委托。
在我的情况下,这个代表永远不会被调用。我认为我错过了一步。在我的委托实施之后(如苹果文档中所述)。
- (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];
}
}];
}
谢谢你的帮助。