【问题标题】:[ios.cocos2d+box2d]how to disable auto-rotation?[ios.cocos2d+box2d]如何禁用自动旋转?
【发布时间】:2010-10-28 06:37:31
【问题描述】:

我用 cocos2d 0.99.5 + box2d 创建了一个项目。 当我旋转我的 iPhone 时,屏幕也会自动旋转。 于是箱子飞到了天花板上。

如何禁用自动旋转?

【问题讨论】:

  • Alur,我们回答你的问题了吗?

标签: iphone ios cocos2d-iphone box2d


【解决方案1】:

在 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;

或者你决定它是你想要的任何方向。希望这会有所帮助!

【讨论】:

    【解决方案2】:

    我的应用程序委托中有这个,无论我以哪种方式转动它,它都保持在横向:

    - (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]];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-18
      • 2014-07-02
      • 2017-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多