排行榜不会在屏幕上添加cocos2d

时间:2011-07-17 15:31:00

标签: 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"];

1 个答案:

答案 0 :(得分:2)

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

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

而不是:

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