我已经用cocos2d 0.99.5 + box2d创建了一个项目。 当我旋转我的iphone时,屏幕也自动旋转。 所以盒子飞入天花板。[ios.cocos2d + box2d]如何禁用自动旋转?
如何禁用自动旋转?
PLZ
我已经用cocos2d 0.99.5 + box2d创建了一个项目。 当我旋转我的iphone时,屏幕也自动旋转。 所以盒子飞入天花板。[ios.cocos2d + box2d]如何禁用自动旋转?
如何禁用自动旋转?
PLZ
我有这个在我的应用程序委托和它停留在景观不管我把它哪条路:
- (void) applicationDidFinishLaunching:(UIApplication*)application
{
// CC_DIRECTOR_INIT()
//
// 1. Initializes an EAGLView with 0-bit depth format, and RGB565 render buffer
// 2. EAGLView multiple touches: disabled
// 3. creates a UIWindow, and assign it to the "window" var (it must already be declared)
// 4. Parents EAGLView to the newly created window
// 5. Creates Display Link Director
// 5a. If it fails, it will use an NSTimer director
// 6. It will try to run at 60 FPS
// 7. Display FPS: NO
// 8. Device orientation: Portrait
// 9. Connects the director to the EAGLView
//
CC_DIRECTOR_INIT();
// Obtain the shared director in order to...
CCDirector *director = [CCDirector sharedDirector];
// Sets landscape mode
[director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];
// Turn on display FPS
[director setDisplayFPS:YES];
// Turn on multiple touches
EAGLView *view = [director openGLView];
[view setMultipleTouchEnabled:YES];
// Default texture format for PNG/BMP/TIFF/JPEG/GIF images
// It can be RGBA8888, RGBA4444, RGB5_A1, RGB565
// You can change anytime.
[CCTexture2D setDefaultAlphaPixelFormat:kTexture2DPixelFormat_RGBA8888];
[[CCDirector sharedDirector] runWithScene: [HelloWorld scene]];
}
在coco2d 0.99.5,模板创建一个名为GameConfig文件。 h,在那里你可以选择什么系统控制应用程序的旋转。默认是
#define GAME_AUTOROTATION kGameAutorotationUIViewController
现在看看RootViewController.m,或者你在文件中命名它的任何东西。在
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
方法,你会看到一些#if
和#elif
编译器指令。检查出kGameAutorotationUIViewController向我们发送的部分:
#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语句改为:
if(interfaceOrientation == UIInterfaceOrientationPortrait)
return YES;
或者是其他的方向,你决定它是你想。希望这可以帮助!
阿尔,我们回答你的问题了吗? – 2010-12-02 13:17:17