GKMatchRequest *request = [GKMatchRequest new];
request.minPlayers = 2;
request.maxPlayers = [GKMatchRequest maxPlayersAllowedForMatchOfType:GKMatchTypeTurnBased];
request.defaultNumberOfPlayers = 2;
GKTurnBasedMatchmakerViewController *controller = [GKTurnBasedMatchmakerViewController.alloc initWithMatchRequest:request];
controller.turnBasedMatchmakerDelegate = self;
[GKDialogController sharedDialogController].parentWindow = self.view.window;
[[GKDialogController sharedDialogController]presentViewController:controller];
GKMatchRequest对象用于指定新的实时或回合制匹配的参数。初始化匹配请求对象,然后将其传递给另一个对象以实际创建匹配。您传递给它的对象类型取决于您想要的匹配类型以及是否要显示标准匹配用户界面。
@property(nonatomic, assign) NSUInteger defaultNumberOfPlayers
比赛的默认球员数。
如果未设置此属性,则默认播放器数等于maxPlayers属性中存储的值。默认播放器数量决定了标准配对用户界面中显示的被邀请者数量。玩家可以选择覆盖它以添加或删除插槽。
答案 0 :(得分:0)
将 defaultNumberOfPlayers 设置为您想要的值。在这种情况下,它被设置为匹配最小数量的玩家。
- (void)findMatchWithMinPlayers:(int)minPlayers maxPlayers:(int)maxPlayers viewController:(UIViewController *)viewController {
if (!gameCenterAvailable) return;
presentingViewController = viewController;
GKMatchRequest *request = [[GKMatchRequest alloc] init];
request.minPlayers = minPlayers;
request.maxPlayers = maxPlayers;
request.defaultNumberOfPlayers = minPlayers;
GKTurnBasedMatchmakerViewController *mmvc = [[GKTurnBasedMatchmakerViewController alloc] initWithMatchRequest:request];
mmvc.turnBasedMatchmakerDelegate = self;
mmvc.showExistingMatches = YES;
[presentingViewController presentViewController:mmvc animated:YES completion:nil];
}