ios - 使用 Cocos2d-x 打开游戏中心 UI

标签 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 上无法运行。它正确连接到沙盒,但未显示 UI,或者更确切地说,UI 位于屏幕外的某个位置。

iPhone 上发生的情况是:

  1. 如果我未登录并访问游戏中心,则会出现登录窗口。当我登录时,什么也没有发生。但是,控制台显示已添加 View 。
  2. 如果我登录并访问游戏中心,则不会发生任何事情。但是,控制台显示已添加 View 。
  3. 如果我在通过身份验证之前访问游戏中心,则会显示游戏中心 UI。然而...
    • 游戏中心处于横向模式(没有问题,因为我的应用处于横向模式),但顶部栏(带有“完成”按钮的栏)的放置方式就好像方向是纵向一样。
    • 未显示整个 UI,仅显示约 30% 的屏幕。

这就是我启动 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 不是一个选项。

最佳答案

试试这个。不要使用“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];
    }

}

关于ios - 使用 Cocos2d-x 打开游戏中心 UI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12526858/

相关文章:

ios - Cocos3D无法二次显示场景

ios - 禁用TableView单元格

ios - 如何将 JWT token 传递给 socket.io swift?

macos - MKMapAnnotationManager 未将自身删除为 MKAnnotation 的观察者

objective-c - 添加/删除由 NSArrayController 管理的 NSMutableArray 的最佳方法

ios - Cocos2d-iphone v3 带 child 的 CCNode 上的触摸事件检测

iphone - 在 cocos2D 中安排具有多个参数的事件

java - 完全在 C++ 中使用 OpenCV Android

iphone - 如何从 3.875 小时中分离和存储小时和分钟

macOS 应用程序 : Don't Let Sync Changes Overwrite User Typing