我想在我自己的游戏中显示leaderbord ....我正在使用以下方法,但注意到发生...我与rootview控制器混淆,因为我的游戏是在cocos2d开发的所以没有像dat一样:(
// Leaderboards
-(void) showLeaderboard
{
if (isGameCenterAvailable == NO)
return;
GKLeaderboardViewController* leaderboardVC = [[[GKLeaderboardViewController alloc] init] autorelease];
if (leaderboardVC != nil)
{
leaderboardVC.leaderboardDelegate = self;
[self presentViewController:leaderboardVC];
}
}
///
-(void) leaderboardViewControllerDidFinish:(GKLeaderboardViewController*)viewController
{
[self dismissModalViewController];
[delegate onLeaderboardViewDismissed];
}
///////
-(UIViewController*) getRootViewController
{
return [UIApplication sharedApplication].keyWindow.rootViewController;
}
///
-(void) presentViewController:(UIViewController*)vc
{
UIViewController* rootVC = [self getRootViewController];
[rootVC presentModalViewController:vc animated:YES];
}
////
-(void) dismissModalViewController
{
UIViewController* rootVC = [self getRootViewController];
[rootVC dismissModalViewControllerAnimated:YES];
}
... 问候
Haseeb
答案 0 :(得分:0)
我不知道,但它对我有用。如果有人能描述为什么这样工作的真正原因我将非常高兴....我通过appdelegate称呼它
[(myAppDelegate*)[[UIApplication sharedApplication] delegate]gameCenter];
从appdelegate我调用rootviewcontroller方法,如
-(void)gameCenter
{
[rootViewController gameCenterLeaderboard];
}
并且在rootviewcontroller中有一个方法
-(void)gameCenterLeaderboard
{
GKLeaderboardViewController* leaderboardVC = [[[GKLeaderboardViewController alloc] init] autorelease];
if (leaderboardVC != nil) {
leaderboardVC.leaderboardDelegate = self;
[self presentModalViewController: leaderboardVC animated: YES];
}
}
以下方法也在rootviewcontroller中重写
- (void)leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)leaderboardController
{
[self dismissModalViewControllerAnimated:YES];
}
答案 1 :(得分:0)
如果您没有根UIViewController,那么我建议创建一个新的UIViewController,将它的视图设置为您的openGLView,然后使用该视图控制器将排行榜呈现为模态视图控制器。
UIViewController *leaderboardViewController = [[UIViewController alloc] init];
[leaderboardViewController setView:[[CCDirector sharedDirector] openGLView]];
[leaderboardViewController presentModalViewController:leaderboardVC animated:YES]; //leaderboardVC is your GKLeaderboardViewController