Mac cocos2d-x 3.8 设置横屏/竖屏

使用命令,新创建一个cocos2d-lua的项目,名为Demo,命令如下:

cocos new Demo -p com.demo.org -l lua -d /Users/用户名/Documents/cocos2d-x-3.8.1/projects

创建成功后,然后使用Xcode打开../projects/Demo/frameworks/runtime-src/proj.ios_mac/Demo.xcodeproj

运行项目,发现是横屏的窗口,然而,我想要竖屏的窗口,其实现步骤如下:

(1) 打开ios/RootViewController.mm,如图所示:

修改函数一:

// Override to allow orientations other than the default portrait orientation.
// This method is deprecated on ios6// Portrait 纵向, Landscape 横向
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    if (SimpleConfigParser::getInstance()->isLanscape()) {
        return UIInterfaceOrientationIsLandscape( interfaceOrientation );
    }else{
        return UIInterfaceOrientationIsPortrait( interfaceOrientation );
    }
}

根据个人需求,可将其改为,如:return UIInterfaceOrientationIsPortrait( interfaceOrientation );

修改函数二:

// For ios6, use supportedInterfaceOrientations & shouldAutorotate instead
- (NSUInteger) supportedInterfaceOrientations{
#ifdef __IPHONE_6_0
    if (SimpleConfigParser::getInstance()->isLanscape()) {
        // 横向
        return UIInterfaceOrientationMaskLandscape;
    }else{
        // 纵向
        return UIInterfaceOrientationMaskPortrait;
    }
#endif
}

根据个人需求,可将其修改为,如: return UIInterfaceOrientationMaskPortrait;

修改函数三:

// 是否支持屏幕旋转
- (BOOL) shouldAutorotate {
    if (SimpleConfigParser::getInstance()->isLanscape()) {
        return YES;
    }else{
        return NO;
    }
}

根据个人需求,可将其修改为,如: return NO;

(2) 修改完代码后,接下来最关键的一点是,点击项目Demo, 选择General, 将其Deployment Info 下的Device Orientation 仅勾选上

Portrait,如图所示:

再次运行,显示出来的就是竖屏了

时间: 2024-08-04 02:47:28

Mac cocos2d-x 3.8 设置横屏/竖屏的相关文章

android 设置横屏竖屏

方法一 代码设置 import android.content.pm.ActivityInfo; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSC

Android设置横屏竖屏

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);//设置成全屏模式 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);//强制为横屏 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_

Android 设置 横屏 竖屏

方法一:在AndroidManifest.xml中配置 如果不想让软件在横竖屏之间切换,最简单的办法就是在项目的AndroidManifest.xml中找到你所指定的activity中加上android:screenOrientation属性,他有以下几个参数: "unspecified":默认值 由系统来判断显示方向.判定的策略是和设备相关的,所以不同的设备会有不同的显示方向. "landscape":横屏显示(宽比高要长) "portrait"

Android之设置横屏竖屏

方案一:在AndroidManifest.xml中配置 在项目的AndroidManifest.xml中找到你所指定的activity中加上android:screenOrientation属性,它有以下几个参数: "unspecified":默认值 由系统来判断显示方向.判定的策略是和设备相关的,所以不同的设备会有不同的显示方向. "landscape":横屏显示(宽比高要长) "portrait":竖屏显示(高比宽要长) "user

Android 设置 横屏 竖屏 (转)

http://2960629.blog.51cto.com/2950629/701227 方法一:在AndroidManifest.xml中配置 如果不想让软件在横竖屏之间切换,最简单的办法就是在项目的AndroidManifest.xml中找到你所指定的activity中加上android:screenOrientation属性,他有以下几个参数: "unspecified":默认值 由系统来判断显示方向.判定的策略是和设备相关的,所以不同的设备会有不同的显示方向. "la

Cocos2dx开发windows phone时,VS2013设置为横屏竖屏问题

1.首先打开自己的windows phone的项目: 2.把项目打开,可看到如下的结构: 3.然后点击MainPage.xaml文件,可以看到如下结构: 然后左边是显示的模拟器,右边是代码,Landscape表示的是横屏,Portrait表示的是竖屏,如图所示: 这样就可以设置横屏竖屏了,如果你只是点击模拟器中的旋转来调试横屏竖屏,根本就没用,还是要代码才能解决吧: 这是在移植wp8的时候一些总结,在移植过程中,各种坑爹的语法都有,有些改了就可以用了,但也许你不知道为什么, 哈哈,真是,可能是兼

cocos2d-x 设置屏幕方向 横屏 || 竖屏

cocos2d-x 设置屏幕方向 横屏 || 竖屏 需要根据各个平台分别进行设置. android 修改项目根目录 proj.android\AndroidManifest.xml 文件中的android:screenOrientation属性值,portrait 为竖屏,landscape为横屏 Windows 直接用cocos引擎接口中的GLView::createWithRect方法指定窗口大小,需要注意的是,该方法在android环境下会报错,并导致程序崩溃,所以我们需要在代码里面这么写

【转】Android 模拟器横屏竖屏切换设置

http://blog.csdn.net/zanfeng/article/details/18355305# Android 模拟器横屏竖屏切换设置时间:2012-07-04   来源:设计与开发   作者:Daniel   点击:5571 摘要:  Android 模拟器旋转,横屏.竖屏切换设置,android 横屏布局,android 横屏模式,android 模拟器,android 模拟器横屏,android 模拟...       Android 模拟器旋转,横屏.竖屏切换设置,andr

cocos2d 设置iphone竖屏

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return UIInterfaceOrientationIsPortrait(interfaceOrientation ); } // For ios6, use supportedInterfaceOrientations & shouldAutorotate instead - (NSUInteger)

手机横屏竖屏css

@media是css3中新定义的,功能非常强大,顾名思义PC是无法匹配横竖屏的,所以orientation只对移动设备起效. 1.头部声明 复制代码 代码如下: <meta name="viewport" content="width=device-width, initial-scale=1.0,user-scalable=no,maximum-scale=1.0"> 加到 复制代码 代码如下: <head></head> 2.