[ios.cocos2d + box2d] как отключить автоповорот? - PullRequest
2 голосов
/ 28 октября 2010

Я создал проект с cocos2d 0.99.5 + box2d.Когда я поворачиваю свой iphone, экран автоматически поворачивается тоже.Значит ящики влетели в потолок.

Как отключить автоповорот?

плз

Ответы [ 2 ]

2 голосов
/ 21 ноября 2010

В 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( interfaceOrientation == UIInterfaceOrientationPortrait)
    return YES;

Или какую бы ориентацию вы ни выбралиэто то, что вы хотите.Надеюсь, это поможет!

0 голосов
/ 21 ноября 2010

У меня есть это в моем делегате приложения, и оно остается в ландшафте независимо от того, в каком направлении я его поверну:

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