回合制游戏中的默认玩家数量? (OS X)

时间:2013-07-08 17:30:21

标签: macos osx-mountain-lion game-center

问:我们如何设置默认的玩家数量?


让我们创建一个带匹配请求的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名默认玩家

Expected

实际:16名默认玩家

Actual

GKMatchRequest类参考

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

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

@property(nonatomic, assign) NSUInteger defaultNumberOfPlayers

比赛的默认球员数。

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

1 个答案:

答案 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];
}