【问题标题】:How do I force portrait mode in Cocos2D?如何在 Cocos2D 中强制人像模式?
【发布时间】:2012-05-06 23:57:55
【问题描述】:

我阅读的每个网页都告诉我编辑“GameConfig.h”文件。我的项目目录中没有这样的文件,如果我尝试导入它,我会收到错误消息。如何在不编辑这个虚幻的头文件的情况下更改我的默认方向?

【问题讨论】:

    标签: iphone xcode cocos2d-iphone portrait


    【解决方案1】:

    您没有说您使用的是哪个版本的 cocos2d,但由于您没有 GameConfig.h 文件,我猜您使用的是 2.0rc。

    如果是这样,请查看 AppDelegate.m,您会发现:

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        return UIInterfaceOrientationIsLandscape(interfaceOrientation);
    }
    

    将横向更改为纵向,这样您现在就有了:

    return UIInterfaceOrientationIsPortrait(interfaceOrientation);
    

    您的游戏将只在两个纵向之间自动旋转。

    【讨论】:

      【解决方案2】:

      在 Cocos2D iPhone v3 中,您可以通过初始设置调用来设置方向,如下所示:

      -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
      {
          [self setupCocos2dWithOptions:@{
                                          CCSetupTabletScale2X: @(YES),
                                          CCSetupScreenOrientation: CCScreenOrientationPortrait
                                          }];
          return YES;
      }
      

      【讨论】:

      • 也在项目设置>常规>部署信息>“设备方向”>检查“纵向”和“倒置”
      【解决方案3】:

      在 Cocos2d v3 中,您必须像往常一样在您的 AppDelegate 中的 didFinishLaunchingWithOptions 方法中设置:

      [self setupCocos2dWithOptions:@{
                                      CCSetupShowDebugStats: @(YES),
                                      CCSetupScreenOrientation: CCScreenOrientationPortrait,
          }];
      

      (我省略的更多选项可用)

      并在项目的 Info.plist 中的语音“支持的界面方向”或“支持的界面方向 (iPad)”下设置纵向而不是横向(iPad 的默认设置)。

      【讨论】:

        猜你喜欢
        • 2013-08-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多