cocos2d HelloWorld 项目横竖屏、自动旋转问题
来源:互联网 发布:mac 怎么下载ps 编辑:程序博客网 时间:2024/06/05 04:34
首先看下 GameConfig.h中的宏定义,配置:
/** * Modified by Bruce Yang on 2012.09.06.13.51~ *//** Supported Autorotations: None, UIViewController, CCDirector */#define kGameAutorotationNone 0#define kGameAutorotationCCDirector 1#define kGameAutorotationUIViewController 2/** Define here the type of autorotation that you want for your game~ *//** * 3rd generation and newer devices: * Rotate using UIViewController. Rotation should be supported on iPad apps. * TIP: * To improve the performance, you should set this value * to "kGameAutorotationNone" or "kGameAutorotationCCDirector" */#if defined(__ARM_NEON__) || TARGET_IPHONE_SIMULATOR#define GAME_AUTOROTATION kGameAutorotationUIViewController/** * ARMv6 (1st and 2nd generation devices): * Don't rotate. It is very expensive */#elif __arm__#define GAME_AUTOROTATION kGameAutorotationNone/** Ignore this value on Mac~ */#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED)/** Unknown architecture~ */#else#error(unknown architecture)#endif如上,定义了三种控制自动旋转的方式:
1。禁用旋转
2。cocos2d 机制的自动旋转控制
3。ios sdk 自身机制的自动旋转控制
默认情况下会采用 ios sdk 自身机制的自动旋转控制~
(项目设计的时候首先决定有无需求做自动旋转,没有的话就用 kGameAutoroationNone
有的话再决定从 kGameAutorotationUIViewController 和 kGameAutorotationCCDirector 里面选一个。
后面二者的区别:
CCDirector 是那种直来直往的,屏幕一翻转它会一步到位将画面翻转过来。
UIViewController 则不一样,旋转的时候他会有个过渡的旋转效果,个人感觉比 CCDirector 那种的体验要好。
不过后者的耗费要比前者高。
另外一个要注意的地方就是,CCDirector 不会对 ui 部件产生影响,举个例子来说明:
如果场景里面有个 UIAlertView 对话框,你旋转屏幕之后 UIAlertView 并不会跟着旋转
那样的话 对话框里面的内容将会倒着呈现。
而 UIViewController 那种就比较聪明,它在将屏幕画面旋转的同时,也会将对话框翻转一下~
------------------------------------------ 分割线 --------------------------------------------
下面接着说一下怎么控制横屏竖屏
将视线的焦点转移到 RootViewController.mm 文件
/** * Override to allow orientations other than the default portrait orientation. * 2012.09.06.14.30,今天仔细看了下旋转这块,比想象中的容易多了,哎~ * 主要还是用默认的 kGameAutorotationUIViewController * 效果比 CCDirector 好(有一个旋转的过渡,而且能让 UI 部件跟着其反应)~ * CCDirector 的话,一下子就翻转了,没有过度,而且不能对 UI 部件如 UIAlertView 做旋转调整~ * 而且,CCDirector 不处理 potrait 的翻转。 * 最后,如果不想启用自动旋转,将 GameConfig 中的 GAME_AUTOROTATION 的值赋为: * kGameAutorotationNone,将会以 portrait 作为默认的显示方式~ */- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {/** Add by Bruce Yang on 2011.10.22.17.27~ */// return 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 */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 (UIInterfaceOrientationIsPortrait(interfaceOrientation)); return (UIInterfaceOrientationIsLandscape(interfaceOrientation));#else#error Unknown value in GAME_AUTOROTATION#endif // GAME_AUTOROTATION// Should not happenreturn NO;}由之前 GAME_AUTOROTATION 被定义成哪种自动旋转的控制类型,走入上面那个方法以后
会进入到相应的分支,默认情况下用的是 GAME_AUTOROTATION = kGameAutorotationUIViewController 的话,
会从 #elif GAME_AUTOROTATION == kGameAutorotationUIViewController 这里开始执行。
上面的代码里面,看下面这两行代码,第一行表示呈现方式为竖屏,第二行表示呈现方式为横屏:
//return (UIInterfaceOrientationIsPortrait(interfaceOrientation));return (UIInterfaceOrientationIsLandscape(interfaceOrientation));
- cocos2d HelloWorld 项目横竖屏、自动旋转问题
- iPhone之横竖屏与自动旋转
- iOS6 横屏项目自动旋转的问题解决 cocos2d
- iOS的横竖屏切换旋转(禁自动旋转)
- android 视频播放 点击横竖屏切换 自动旋转横竖屏切换 冲突
- LAUNCHER横竖屏旋转后长按不能生效的问题
- Android 设定横竖屏,屏幕旋转导致Activity重置问题
- android怎样实现关闭系统自动旋转屏幕时能够自动横竖屏
- [cocos2d-x 3.0] 横竖屏、屏幕分辨率的问题
- iOS之横竖屏旋转
- iOS之横竖屏旋转
- iOS 横竖屏旋转处理
- h5 监听 横竖屏 旋转
- Android系统实现横竖屏两方向自动旋转的方法
- Mono For Android 如何控制程序在自动旋转功能开启下不进行横竖屏切换
- cocos2d-x设置横竖屏
- widget中自动横竖屏切换时的问题
- iOS项目不支持横屏的前提下某个界面横竖屏(旋转)的解决方案
- MINI GUI 上的helloworld 程序
- C# MD5 加密方法
- HDU 4111--Alice and Bob
- VMware(VMDebugger)导致VS2010启动慢的解决办法
- 立方体纹理(cube map)
- cocos2d HelloWorld 项目横竖屏、自动旋转问题
- MINI GUI 加载位图
- C语言---“C语言 谁与争锋?”
- WebBrowser直接写入内容
- MINI GUI绘图
- 全面的framebuffer详解
- stm32f407之MyDebugger(操作寄存器)
- 返回时 刷新要返回页面
- 大学操作系统教程的不足之处