ios - cocos2d 屏幕上没有添加排行榜

标签 ios cocos2d-iphone shared-libraries game-center leaderboard

我使用下面的代码来显示排行榜,但我得到的只是控制台

cocos2d: surface size: 480x320

代码:

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

最后我这样调用代码:

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

最佳答案

我找到了我必须写的解决方案:

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

而不是:

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

关于ios - cocos2d 屏幕上没有添加排行榜,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6724844/

相关文章:

ios - 从字符串中获取范围

ios - UITableView 标题 View 宽度

iPhone 游戏开发与 Cocos2d : how to generate a cool light effect when an entity gets hit?

c - 为什么 C 库链接顺序只在某些系统上很重要?

c++ - Gcc 隐藏来自包含的静态库的符号的可见性

ios - 如何在同一设备不同账号下执行ios IAP

ios - 当通过文件 URL 共享时,UIActivityViewController 认为我的 jpg 是视频

iphone - cocos2d : Show entire layer then zoom in on character

iphone - 将皮肤/主题添加到 iPhone 应用程序

c - 使用 GCC 在共享库中启用调试符号