[ios.cocos2d+box2d]how to disable auto-rotation?([ios.cocos2d+box2d]如何禁用自动旋转?)
问题描述
我用 cocos2d 0.99.5 + box2d 创建了一个项目.当我旋转我的 iPhone 时,屏幕也会自动旋转.于是箱子飞到了天花板上.
I have created a project with cocos2d 0.99.5 + box2d. When I rotate my iphone, Screen automatically rotated too. So the boxes Flew up into the ceiling.
如何禁用自动旋转?
请
推荐答案
在 coco2d 0.99.5 中,模板会创建一个名为 GameConfig.h 的文件,您可以在其中选择控制应用旋转的系统.默认是
In coco2d 0.99.5, the template creates a file called GameConfig.h, where you get to choose what system controls the app's rotation. The default is
#define GAME_AUTOROTATION kGameAutorotationUIViewController
现在看看 RootViewController.m 内部,或者你在文件中命名的任何内容.在
Now take a look inside RootViewController.m, or whatever you've named it in your file. in the
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
方法,您将看到许多 #if 和 #elif 编译器指令.查看 kGameAutorotationUIViewController 发送给我们的部分:
method, you'll see a number of #if and #elif compiler directives. Check out the section that kGameAutorotationUIViewController sends us to:
#elif GAME_AUTOROTATION == kGameAutorotationUIViewController
//
// EAGLView will be rotated by the UIViewController
//
// Sample: Autorotate only in landscpe mode
//
// return YES for the supported orientations
if( interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
interfaceOrientation == UIInterfaceOrientationLandscapeRight )
return YES;
// Unsupported orientations:
// UIInterfaceOrientationPortrait, UIInterfaceOrientationPortraitUpsideDown
return NO;
要使您的游戏保持单一方向,请将中间的 if 语句更改为:
To keep your game at a single orientation, change that middle if statement to read:
if( interfaceOrientation == UIInterfaceOrientationPortrait)
return YES;
或者你决定它是你想要的任何方向.希望这会有所帮助!
Or whatever orientation you decide it is that you want. Hope this helps!
这篇关于[ios.cocos2d+box2d]如何禁用自动旋转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:[ios.cocos2d+box2d]如何禁用自动旋转?
基础教程推荐
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- iOS4 创建后台定时器 2022-01-01
