首页 > 系统服务 > 详细

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

时间:2016-03-11 22:14:29      阅读:293      评论:0      收藏:0      [点我收藏+]

使用命令,新创建一个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,如图所示:

技术分享

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

 

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

原文:http://www.cnblogs.com/SkyflyBird/p/5267369.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!