Leaderboard doesn't add in the screen cocos2d

柔情痞子 提交于 2019-12-12 15:04:30

问题


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

Finally I called the code like this :

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

回答1:


I found the solution I must write :

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

instead of :

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


来源:https://stackoverflow.com/questions/6724844/leaderboard-doesnt-add-in-the-screen-cocos2d

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