加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

quick-cocos2d-x 如何设置游戏的屏幕方向

发布时间:2020-12-14 19:24:38 所属栏目:百科 来源:网络整理
导读:quick 中的 create_project 工具在创建项目时,可以用 -o 参数指定屏幕方向。但如果要修改已有项目的屏幕方向,就要按如下步骤进行。 对于 iOS 项目 设置工程可用的屏幕方向: 找到 RootViewController.mm 文件,做如下修改: 如果需要横屏: - ( BOOL )shou

quick 中的 create_project 工具在创建项目时,可以用 -o 参数指定屏幕方向。但如果要修改已有项目的屏幕方向,就要按如下步骤进行。

对于 iOS 项目

  1. 设置工程可用的屏幕方向:

  2. 找到 RootViewController.mm 文件,做如下修改:

    如果需要横屏:

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        return UIInterfaceOrientationIsLandscape(interfaceOrientation);
    }
    
    // For ios6.0 and higher,use supportedInterfaceOrientations & shouldAutorotate instead
    - (NSUInteger) supportedInterfaceOrientations
    {
    #ifdef __IPHONE_6_0
        return UIInterfaceOrientationMaskLandscape;
    #endif
    }

    如果需要竖屏:

    - (UIInterfaceOrientation)interfaceOrientation
    {
        return UIInterfaceOrientationIsPortrait(interfaceOrientation);
    }
    
    #ifdef __IPHONE_6_0
        return UIInterfaceOrientationMaskPortrait;
    #endif
    }
  3. 按照 Apple 文档要求,制作不同屏幕方向需要的启动画面文件 (Default.png)。文档地址:iOS Human Interface Guidelines – Launch Images

对于 Android 项目

修改 AndroidManifest.xml 文件中的 android:screenOrientation 属性:

  • landscape 横屏
  • portrait 竖屏

修改 config.lua 配置

如果需要横屏:

-- design resolution
CONFIG_SCREEN_WIDTH  = 960
CONFIG_SCREEN_HEIGHT = 640
CONFIG_SCREEN_ORIENTATION = "landscape"

-- auto scale mode
CONFIG_SCREEN_AUTOSCALE = "FIXED_HEIGHT"

如果需要竖屏:

640
CONFIG_SCREEN_HEIGHT = 960
CONFIG_SCREEN_ORIENTATION = "portrait"

"FIXED_WIDTH"

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读