cocos2d 屏幕默认是横屏,修改为竖屏 的方法

2024-01-29 11:58

本文主要是介绍cocos2d 屏幕默认是横屏,修改为竖屏 的方法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

在RootViewController.m文件里面,修改如下代码

的方法shouldAutorotateToInterfaceOrientation 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {//// There are 2 ways to support auto-rotation://  - The OpenGL / cocos2d way//     - Faster, but doesn't rotate the UIKit objects//  - The ViewController way//    - A bit slower, but the UiKit objects are placed in the right place//#if GAME_AUTOROTATION==kGameAutorotationNone//// EAGLView won't be autorotated.// Since this method should return YES in at least 1 orientation, // we return YES only in the Portrait orientation//return ( interfaceOrientation == UIInterfaceOrientationPortrait );#elif GAME_AUTOROTATION==kGameAutorotationCCDirector//// EAGLView will be rotated by cocos2d//// Sample: Autorotate only in landscape mode//if( interfaceOrientation == UIInterfaceOrientationLandscapeLeft ) {[[CCDirector sharedDirector] setDeviceOrientation: kCCDeviceOrientationLandscapeRight];} else if( interfaceOrientation == UIInterfaceOrientationLandscapeRight) {[[CCDirector sharedDirector] setDeviceOrientation: kCCDeviceOrientationLandscapeLeft];}// Since this method should return YES in at least 1 orientation, // we return YES only in the Portrait orientationreturn ( interfaceOrientation == UIInterfaceOrientationPortrait );#elif GAME_AUTOROTATION == kGameAutorotationUIViewController//// EAGLView will be rotated by the UIViewController//// Sample: Autorotate only in landscpe mode//// return YES for the supported orientations// 横屏//return ( UIInterfaceOrientationIsLandscape( interfaceOrientation ) );return ( UIInterfaceOrientationIsPortrait( interfaceOrientation ) );//坚屏#else
#error Unknown value in GAME_AUTOROTATION#endif // GAME_AUTOROTATION// Shold not happenreturn NO;
}


//

// There are 2 ways to support auto-rotation:

//  - The OpenGL / cocos2d way

//     - Faster, but doesn't rotate the UIKit objects

//  - The ViewController way

//    - A bit slower, but the UiKit objects are placed in the right place

//

#if GAME_AUTOROTATION==kGameAutorotationNone

//

// EAGLView won't be autorotated.

// Since this method should return YES in at least 1 orientation, 

// we return YES only in the Portrait orientation

//

return ( interfaceOrientation == UIInterfaceOrientationPortrait );

#elif GAME_AUTOROTATION==kGameAutorotationCCDirector

//

// EAGLView will be rotated by cocos2d

//

// Sample: Autorotate only in landscape mode

//

ifinterfaceOrientation == UIInterfaceOrientationLandscapeLeft ) {

[[CCDirector sharedDirector] setDeviceOrientation: kCCDeviceOrientationLandscapeRight];

else

这篇关于cocos2d 屏幕默认是横屏,修改为竖屏 的方法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/656825

相关文章

Python安装Pandas库的两种方法

《Python安装Pandas库的两种方法》本文介绍了三种安装PythonPandas库的方法,通过cmd命令行安装并解决版本冲突,手动下载whl文件安装,更换国内镜像源加速下载,最后建议用pipli... 目录方法一:cmd命令行执行pip install pandas方法二:找到pandas下载库,然后

Linux系统中查询JDK安装目录的几种常用方法

《Linux系统中查询JDK安装目录的几种常用方法》:本文主要介绍Linux系统中查询JDK安装目录的几种常用方法,方法分别是通过update-alternatives、Java命令、环境变量及目... 目录方法 1:通过update-alternatives查询(推荐)方法 2:检查所有已安装的 JDK方

SQL Server安装时候没有中文选项的解决方法

《SQLServer安装时候没有中文选项的解决方法》用户安装SQLServer时界面全英文,无中文选项,通过修改安装设置中的国家或地区为中文中国,重启安装程序后界面恢复中文,解决了问题,对SQLSe... 你是不是在安装SQL Server时候发现安装界面和别人不同,并且无论如何都没有中文选项?这个问题也

Java Thread中join方法使用举例详解

《JavaThread中join方法使用举例详解》JavaThread中join()方法主要是让调用改方法的thread完成run方法里面的东西后,在执行join()方法后面的代码,这篇文章主要介绍... 目录前言1.join()方法的定义和作用2.join()方法的三个重载版本3.join()方法的工作原

Spring Boot 中的默认异常处理机制及执行流程

《SpringBoot中的默认异常处理机制及执行流程》SpringBoot内置BasicErrorController,自动处理异常并生成HTML/JSON响应,支持自定义错误路径、配置及扩展,如... 目录Spring Boot 异常处理机制详解默认错误页面功能自动异常转换机制错误属性配置选项默认错误处理

在MySQL中实现冷热数据分离的方法及使用场景底层原理解析

《在MySQL中实现冷热数据分离的方法及使用场景底层原理解析》MySQL冷热数据分离通过分表/分区策略、数据归档和索引优化,将频繁访问的热数据与冷数据分开存储,提升查询效率并降低存储成本,适用于高并发... 目录实现冷热数据分离1. 分表策略2. 使用分区表3. 数据归档与迁移在mysql中实现冷热数据分

Spring Boot从main方法到内嵌Tomcat的全过程(自动化流程)

《SpringBoot从main方法到内嵌Tomcat的全过程(自动化流程)》SpringBoot启动始于main方法,创建SpringApplication实例,初始化上下文,准备环境,刷新容器并... 目录1. 入口:main方法2. SpringApplication初始化2.1 构造阶段3. 运行阶

Olingo分析和实践之ODataImpl详细分析(重要方法详解)

《Olingo分析和实践之ODataImpl详细分析(重要方法详解)》ODataImpl.java是ApacheOlingoOData框架的核心工厂类,负责创建序列化器、反序列化器和处理器等组件,... 目录概述主要职责类结构与继承关系核心功能分析1. 序列化器管理2. 反序列化器管理3. 处理器管理重要方

Python错误AttributeError: 'NoneType' object has no attribute问题的彻底解决方法

《Python错误AttributeError:NoneTypeobjecthasnoattribute问题的彻底解决方法》在Python项目开发和调试过程中,经常会碰到这样一个异常信息... 目录问题背景与概述错误解读:AttributeError: 'NoneType' object has no at

postgresql使用UUID函数的方法

《postgresql使用UUID函数的方法》本文给大家介绍postgresql使用UUID函数的方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录PostgreSQL有两种生成uuid的方法。可以先通过sql查看是否已安装扩展函数,和可以安装的扩展函数