使用 GKLeaderboardViewController 时的方向问题

发布于 2024-11-25 02:48:17 字数 1612 浏览 1 评论 0原文

不幸的是,我不太了解 UIViewController,也不太了解它们如何与 cocos2d 场景相结合。不过,我能够在 iPhone 上成功地在我的 cocos2d(仅限横向)游戏之上加载标准 Game Center 排行榜视图。但是,我的游戏是一款通用应用程序,当我在 iPad 上尝试时,游戏中心视图以纵向加载,大约是应有尺寸的一半(仅填充屏幕的四分之一),并且不居中。当我旋转设备时,Game Center 视图将自身定向为横向,但实际上会被拉伸,看起来不是为横向视图中的 iPad 设计的。

有人有什么建议吗?

- (void) showLeaderboard
{
    if(![MyAppDelegate isGameCenterAPIAvailable])   
        return;

    if ([GKLocalPlayer localPlayer].isAuthenticated == YES)
    {
        CGSize screenSize = [[UIScreen mainScreen] bounds].size;
        tempVC = [[RootViewController alloc] init];
        GKLeaderboardViewController *leaderboard = [[[GKLeaderboardViewController alloc] init] autorelease];
        if (leaderboard != NULL)
        {
            leaderboard.leaderboardDelegate = self;
            [[[CCDirector sharedDirector] openGLView] addSubview:tempVC.view];

            // Pause game
            [[CCDirector sharedDirector] pause];

            [tempVC presentModalViewController:leaderboard animated: NO];
            leaderboard.view.transform = CGAffineTransformMakeRotation(CC_DEGREES_TO_RADIANS(0.0f));
            [leaderboard.view setCenter:CGPointMake(screenSize.height/2, screenSize.width/2)];
            leaderboard.modalPresentationStyle = UIModalPresentationCurrentContext;
        }
    }
}

- (void)leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController
{
    [tempVC dismissModalViewControllerAnimated: YES];
    [tempVC.view.superview removeFromSuperview];
    [tempVC release];
    tempVC = nil;

    // Resume game
    [[CCDirector sharedDirector] resume];
}

Unfortunately, I don't understand UIViewControllers very well, nor do I understand exactly how they mesh with cocos2d scenes. However, I am able to load a standard Game Center leaderboard view on top of my cocos2d (landscape-only) game successfully on the iPhone. But, my game is a universal app and when I try it on iPad, the Game Center view loads in portrait orientation, is about half the size it should be (fills up only one quarter of the screen), and is not centered. When I rotate the device, the Game Center view orients itself to landscape but gets really stretched out and looks like it wasn't designed for iPad in landscape view.

Does anyone have any advice?

- (void) showLeaderboard
{
    if(![MyAppDelegate isGameCenterAPIAvailable])   
        return;

    if ([GKLocalPlayer localPlayer].isAuthenticated == YES)
    {
        CGSize screenSize = [[UIScreen mainScreen] bounds].size;
        tempVC = [[RootViewController alloc] init];
        GKLeaderboardViewController *leaderboard = [[[GKLeaderboardViewController alloc] init] autorelease];
        if (leaderboard != NULL)
        {
            leaderboard.leaderboardDelegate = self;
            [[[CCDirector sharedDirector] openGLView] addSubview:tempVC.view];

            // Pause game
            [[CCDirector sharedDirector] pause];

            [tempVC presentModalViewController:leaderboard animated: NO];
            leaderboard.view.transform = CGAffineTransformMakeRotation(CC_DEGREES_TO_RADIANS(0.0f));
            [leaderboard.view setCenter:CGPointMake(screenSize.height/2, screenSize.width/2)];
            leaderboard.modalPresentationStyle = UIModalPresentationCurrentContext;
        }
    }
}

- (void)leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController
{
    [tempVC dismissModalViewControllerAnimated: YES];
    [tempVC.view.superview removeFromSuperview];
    [tempVC release];
    tempVC = nil;

    // Resume game
    [[CCDirector sharedDirector] resume];
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏了南城 2024-12-02 02:48:17

请查看在 Cocos2d 应用程序中实现 iAds。

[self.view addSubview:self.bannerView];

在本教程中,将Subview UIView对象添加到RootViewController.view(即cocos2d应用程序模板中),而不是EAGLView。

Please take a look at Implementing iAds in Cocos2d Application.

[self.view addSubview:self.bannerView];

In this tutorial, addSubview UIView object to RootViewController.view, that is in the cocos2d application template, instead of EAGLView.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文