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

相关文章

Java中读取YAML文件配置信息常见问题及解决方法

《Java中读取YAML文件配置信息常见问题及解决方法》:本文主要介绍Java中读取YAML文件配置信息常见问题及解决方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要... 目录1 使用Spring Boot的@ConfigurationProperties2. 使用@Valu

c++ 类成员变量默认初始值的实现

《c++类成员变量默认初始值的实现》本文主要介绍了c++类成员变量默认初始值,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧... 目录C++类成员变量初始化c++类的变量的初始化在C++中,如果使用类成员变量时未给定其初始值,那么它将被

Java 方法重载Overload常见误区及注意事项

《Java方法重载Overload常见误区及注意事项》Java方法重载允许同一类中同名方法通过参数类型、数量、顺序差异实现功能扩展,提升代码灵活性,核心条件为参数列表不同,不涉及返回类型、访问修饰符... 目录Java 方法重载(Overload)详解一、方法重载的核心条件二、构成方法重载的具体情况三、不构

SQL中如何添加数据(常见方法及示例)

《SQL中如何添加数据(常见方法及示例)》SQL全称为StructuredQueryLanguage,是一种用于管理关系数据库的标准编程语言,下面给大家介绍SQL中如何添加数据,感兴趣的朋友一起看看吧... 目录在mysql中,有多种方法可以添加数据。以下是一些常见的方法及其示例。1. 使用INSERT I

Python中反转字符串的常见方法小结

《Python中反转字符串的常见方法小结》在Python中,字符串对象没有内置的反转方法,然而,在实际开发中,我们经常会遇到需要反转字符串的场景,比如处理回文字符串、文本加密等,因此,掌握如何在Pyt... 目录python中反转字符串的方法技术背景实现步骤1. 使用切片2. 使用 reversed() 函

Python中将嵌套列表扁平化的多种实现方法

《Python中将嵌套列表扁平化的多种实现方法》在Python编程中,我们常常会遇到需要将嵌套列表(即列表中包含列表)转换为一个一维的扁平列表的需求,本文将给大家介绍了多种实现这一目标的方法,需要的朋... 目录python中将嵌套列表扁平化的方法技术背景实现步骤1. 使用嵌套列表推导式2. 使用itert

Python使用pip工具实现包自动更新的多种方法

《Python使用pip工具实现包自动更新的多种方法》本文深入探讨了使用Python的pip工具实现包自动更新的各种方法和技术,我们将从基础概念开始,逐步介绍手动更新方法、自动化脚本编写、结合CI/C... 目录1. 背景介绍1.1 目的和范围1.2 预期读者1.3 文档结构概述1.4 术语表1.4.1 核

在Linux中改变echo输出颜色的实现方法

《在Linux中改变echo输出颜色的实现方法》在Linux系统的命令行环境下,为了使输出信息更加清晰、突出,便于用户快速识别和区分不同类型的信息,常常需要改变echo命令的输出颜色,所以本文给大家介... 目python录在linux中改变echo输出颜色的方法技术背景实现步骤使用ANSI转义码使用tpu

Conda与Python venv虚拟环境的区别与使用方法详解

《Conda与Pythonvenv虚拟环境的区别与使用方法详解》随着Python社区的成长,虚拟环境的概念和技术也在不断发展,:本文主要介绍Conda与Pythonvenv虚拟环境的区别与使用... 目录前言一、Conda 与 python venv 的核心区别1. Conda 的特点2. Python v

Spring Boot中WebSocket常用使用方法详解

《SpringBoot中WebSocket常用使用方法详解》本文从WebSocket的基础概念出发,详细介绍了SpringBoot集成WebSocket的步骤,并重点讲解了常用的使用方法,包括简单消... 目录一、WebSocket基础概念1.1 什么是WebSocket1.2 WebSocket与HTTP