我正在为我的游戏开发多人游戏,我遇到了以下问题我正在使用Cocos 2d 2.1,iOS 6和以下代码来显示红娘(横向)
AppController *app = (AppController*) [[UIApplication sharedApplication] delegate];
[[GCHelper sharedInstance] findMatchWithMinPlayers:2 maxPlayers:4 viewController:[app navController] delegate:self];
这就是它如何出现
以下代码用于该功能
- (void)findMatchWithMinPlayers:(int)minPlayers maxPlayers:(int)maxPlayers
viewController:(UIViewController *)viewController
delegate:(id<GCHelperDelegate>)theDelegate {
if (!gameCenterAvailable) return;
matchStarted = NO;
self.match = nil;
self.presentingViewController = viewController;
delegate = theDelegate;
[presentingViewController dismissModalViewControllerAnimated:NO];
GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease];
request.minPlayers = minPlayers;
request.maxPlayers = maxPlayers;
GKMatchmakerViewController *mmvc =
[[[GKMatchmakerViewController alloc] initWithMatchRequest:request] autorelease];
mmvc.matchmakerDelegate = self;
[presentingViewController presentViewController:mmvc animated:YES completion:nil];
}
2 回答
这是HelloWorldLayer中的代码吗?如果那是导演所说的第一层?我有同样的问题,但如果我严格遵循为我创建的cocos2d模板,它会修复 . 这意味着我使用IntroLayer作为初始层,并从那里转换到我拥有游戏中心代码的HelloWorldLayer . 我认为它与导演加载太晚有关,但我不确定
当您尝试按
UIViewController
但 you only have a UIView in your app, and no UIViewController 时会发生这种情况 . 让我猜,你没有rootViewController
.如果您使用
EAGLView
模板, you must declare a UIViewController for the UIView . 这可以很简单,然后,无论何时你想推送其中一个GameKit
UIViewControllers
,使用你的Window对象的presentViewController
方法rootViewController
例如:
bugginess将消失,窗口将正确形成 .