2

cocos2d 0.99.5 + box2d でプロジェクトを作成しました。iPhoneを回転させると、画面も自動的に回転しました。それで箱は天井に飛んだ。

自動回転を無効にする方法は?

お願いします

4

2 に答える 2

2

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-11-21T01:30:42.023 に答える
0

私はこれをアプリケーションデリゲートに持っており、どちらの方向に向けても横向きのままです。

- (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]];
}
于 2010-11-21T01:18:43.833 に答える