4

Q:我们如何设置默认玩家人数?


让我们创建一个带有匹配请求的 GKTurnBasedMatchmakerViewController:

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];

预期:2 个默认玩家

预期的

实际:16 个默认玩家

实际的

GKMatchRequest 类参考

GKMatchRequest 对象用于指定新的实时或回合制比赛的参数。您初始化一个匹配请求对象,然后将其传递给另一个对象以实际创建匹配。您将其传递给的对象类型取决于您想要的匹配类型以及是否要显示标准匹配用户界面。

https://developer.apple.com/library/mac/#documentation/GameKit/Reference/GKMatchRequest_Ref/Reference/Reference.html

@property(nonatomic, assign) NSUInteger defaultNumberOfPlayers

比赛的默认玩家人数。

如果未设置此属性,则默认玩家数等于存储在 maxPlayers 属性中的值。默认玩家数量决定了标准匹配用户界面中显示的受邀者数量。玩家可以选择覆盖它以添加或删除插槽。

4

1 回答 1

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];
}
于 2014-05-11T16:40:32.403 回答