使用Cocos2d-x打开Game Center UI

时间:2012-09-21 08:27:54

标签: ios cocoa cocos2d-iphone game-center cocos2d-x

我已设置好以便我的应用可以连接到游戏中心。我按照this指南编写了一个C ++类包装器,在我的其他类中调用它们。我正在使用iPad(iOS 5.1),iPod Touch第四代(iOS 5.1)以及iPhone 4s和3GS进行测试。它在iPad设备上运行良好但由于某些未知原因,它不适用于iPhone和iPod。它正确地连接到Sandbox但是UI没有显示,或者说UI在屏幕外的某个地方。

iPhone上发生的事情是:

  1. 如果我没有登录并访问游戏中心,则会出现一个登录窗口。当我登录时,没有任何反应。但是,控制台说添加了一个视图。
  2. 如果我已登录并访问游戏中心,则不会发生任何事情。但是,控制台说添加了一个视图。
  3. 如果在我通过身份验证之前访问游戏中心,则会显示Game Center UI。然而...
    • 游戏中心处于横向模式(没有任何问题,因为我的应用程序处于横向状态),但顶部栏(带有DONE按钮的栏)的位置就像是纵向一样。
    • 整个用户界面未显示,仅占屏幕的约30%。
  4. 这就是我启动Game Center UI的方式:

    - (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 = GKLeaderboardTimeScopeToday;  // GKLeaderboardTimeScopeToday, GKLeaderboardTimeScopeWeek, GKLeaderboardTimeScopeAllTime
    
                // Create an additional UIViewController to attach the GKLeaderboardViewController to
                myViewController = [[UIViewController alloc] initWithNibName:nil bundle:nil ];
    
                // Add the temporary UIViewController to the main OpenGL view
                // NOTE: This is the part that I think is the suspect. I am not sure if iPhones and iPods support EAGLView.
                [ [ EAGLView sharedEGLView ] addSubview:myViewController.view ];
    
                // Tell UIViewController to present the leaderboard
                [ myViewController presentModalViewController:leaderboardController animated:NO ];
                NSLog( @"Leaderboard opened." );
            }
        }
    }
    

    任何帮助都表示赞赏,并提前致谢。

    编辑:使用OpenFeint不是一种选择。

1 个答案:

答案 0 :(得分:2)

试试这个。不要使用'EAGLView'

- (void) showLeaderboard
{
    if (!gameCenterAvailable) return;

    GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init];
    if (leaderboardController != nil) {
        leaderboardController.leaderboardDelegate = self;

        UIWindow *window = [[UIApplication sharedApplication] keyWindow];
        currentModalViewController = [[UIViewController alloc] init];
        [window addSubview:currentModalViewController.view];
        [currentModalViewController presentModalViewController:leaderboardController animated:YES];
    }

}