开发者

Trouble with matchmaking in iOS with gamekit and game centre

开发者 https://www.devze.com 2023-04-06 18:55 出处:网络
At the moment I\'m trying to add online multiplayer to my iOS game (that uses UIKit) using gameKit/GameCenter for matchmaking. I\'m trying to present game center\'s matchmaker interface but with varie

At the moment I'm trying to add online multiplayer to my iOS game (that uses UIKit) using gameKit/GameCenter for matchmaking. I'm trying to present game center's matchmaker interface but with varied success. I have two view controllers (with respective .xib files), mainMenuViewController and onlineViewController, along with a file called GCHelper.h.

In CGHelper I have this:

- (void)findMatchWithMinPlayers:(int)minPlayers
                     maxPlayers:(int)maxPlayers 
                 viewController:(UIViewController *)viewController             
                       delegate:(id<GCHelperDelegate>)theDelegate 
{
    if (!gameCenterAvailable) return;   

    self.presentingViewController = viewController;
    delegate = theDelegate;               
    [presentingViewController dismissModalViewControllerAnimated:NO];

    GKMatchRequest *request = [[GKMatchRequest alloc] init]; 
    request.minPlayers = minPlayers;     
    request.maxPlayers = maxPlayers;

    GKMatchmakerViewController *mmvc = [[GKMatchmakerViewController alloc] initWithMatchRequest:request];    
    mmvc.matchmakerDelegate = self;

    [presentingViewController presentModalViewController:mmvc animated:YES];
}

I use this function in my views to show the matchmaking interface. At first I tried it in mainMenuViewController, which is my first view controller using this:

[[GCHelper sharedInstance] findMatchWithMinPlayers:2 maxPlayers:2 viewController:self delegate:self];

And that worked fine but that's not where I wanted to do it, so I tried the exact same thing from onlineViewController and nothing happens, no error, just the blank view of onlineViewController.view stares back at me. I'm fairly new at this so I'm wondering if it's down to how I'm dealing with the views, here's the code I use to switch from the mainMenu to the other view:

-(IBAction)showOnlineView 
{
    OnlineViewController *onlineViewController = [[OnlineViewController alloc] initWithNibName:@"OnlineViewController" bundle:nil];
    UIView *currentView = self.view;
    UIView *theWindow = [currentView superview];
    [currentView removeFromSuperview];
    [theWindow addSubview:onlineViewController.view];
}

Any help would be greatly appreciated. Also, I'm not sur开发者_如何学运维e how I should deal with going back to the main menu if the user presses cancel (although that may become self evident once I've got this working, I just thought I'd mention it in case this lack of knowledge on my part makes it obvious I'm going about the whole thing incorrectly).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号