排行榜没有添加到屏幕 cocos2d屏幕、排行榜、cocos2d

2023-09-06 14:57:28 作者:唯独

I used the code below to show the Leaderboard but all i got it the console this

cocos2d: surface size: 480x320

the code:

- (void)showLeaderboardForCategory:(NSString *)category
{
    // Only execute if OS supports Game Center & player is logged in
    if (hasGameCenter)
    {    

        // Create leaderboard view w/ default Game Center style
        GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init];

        // If view controller was successfully created...
        if (leaderboardController != nil)
        {
            // Leaderboard config
            leaderboardController.leaderboardDelegate = self;   // The leaderboard view controller will send messages to this object
            leaderboardController.category = category;  // Set category here
            leaderboardController.timeScope = GKLeaderboardTimeScopeAllTime;    // GKLeaderboardTimeScopeToday, GKLeaderboardTimeScopeWeek, GKLeaderboardTimeScopeAllTime

            // Create an additional UIViewController to attach the GKLeaderboardViewController to
            myViewController = [[UIViewController alloc] init];

            // Add the temporary UIViewController to the main OpenGL view
            [[[CCDirector sharedDirector] openGLView] addSubview:myViewController.view];

            // Tell UIViewController to present the leaderboard
            [myViewController presentModalViewController:leaderboardController animated:YES];
        }
    }
}
译 cocos2d x跨android ios平台开发入门教程

Finally I called the code like this :

    [[GameCenterManager sharedGameCenterManager] showLeaderboardForCategory:@"LeaderBoard"];

解决方案

I found the solution I must write :

    [[[[CCDirector sharedDirector] openGLView] window] addSubview:myViewController.view];

instead of :

    [[[CCDirector sharedDirector] openGLView] addSubview:myViewController.view];