IPhone如何显示排行榜屏幕在我自己的游戏....在cocos2d开发

IPhone如何显示排行榜屏幕在我自己的游戏....在cocos2d开发

问题描述:

我想在我自己的游戏中显示leaderbord ....我使用以下方法,但注意到发生...我混淆了rootview控制器,因为我的游戏是在cocos2d开发的,所以没有像dat:

i want to show leaderbord in my own game ....i am using following method for that but noting happen ... i am confuse with rootview controller as my game is developed in cocos2d so there is nothing like 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];
}

...

... regards

Haseeb

我不知道,但它适用于我。任何人都可以描述真正的原因为什么这种工作方式我会很高兴...我通过appdelegate

i dont know but it work for me.if anyone can describe the real reason for why this working in this way i will be very glad....i call it through appdelegate

[(myAppDelegate*)[[UIApplication sharedApplication] delegate]gameCenter];

并从appdelegate i调用rootviewcontroller方法

and from appdelegate i call rootviewcontroller method like

-(void)gameCenter
{
    [rootViewController gameCenterLeaderboard];
}

,在rootviewcontroller中有一个方法

and in rootviewcontroller there is a method

-(void)gameCenterLeaderboard
{

    GKLeaderboardViewController* leaderboardVC = [[[GKLeaderboardViewController alloc] init] autorelease];
    if (leaderboardVC != nil) {

        leaderboardVC.leaderboardDelegate = self; 
        [self presentModalViewController: leaderboardVC animated: YES];


    }

}

以下方法也在rootviewcontroller中覆盖

the following method is also override in rootviewcontroller

- (void)leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)leaderboardController
{

    [self dismissModalViewControllerAnimated:YES];
}