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

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

对于 iOS 项目

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

    xcode_project_screen_-orientation_01

  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
    }

    如果需要竖屏:

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        return UIInterfaceOrientationIsPortrait(interfaceOrientation);
    }
    
    // For ios6.0 and higher, use supportedInterfaceOrientations & shouldAutorotate instead
    - (NSUInteger) supportedInterfaceOrientations
    {
    #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"

如果需要竖屏:

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

-- auto scale mode
CONFIG_SCREEN_AUTOSCALE = "FIXED_WIDTH"

转载于:https://my.oschina.net/fgreshrht/blog/378936

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值