IPhone how do display Leaderboard screen in my own game … developed in cocos2d

我是研究僧i 提交于 2019-12-11 04:34:18

问题


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


回答1:


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];

and from appdelegate i call rootviewcontroller method like

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

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];


    }

}

the following method is also override in rootviewcontroller

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

    [self dismissModalViewControllerAnimated:YES];
}



回答2:


If you don't have a root UIViewController then I'd recommend creating a new UIViewController set it's view to your openGLView then use that view controller to present the leaderboard as a modal view controller.

UIViewController *leaderboardViewController = [[UIViewController alloc] init];
[leaderboardViewController setView:[[CCDirector sharedDirector] openGLView]];

[leaderboardViewController presentModalViewController:leaderboardVC animated:YES]; //leaderboardVC is your GKLeaderboardViewController


来源:https://stackoverflow.com/questions/5803522/iphone-how-do-display-leaderboard-screen-in-my-own-game-developed-in-cocos2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!