2012-10-16 74 views
0

這是我應用程序的最後一步,其他一切都完成了。如何僅使用Cocos2d旋轉風景

我正在使用cocos2d,無論我做什麼,我都無法讓應用程序旋轉。它只能以我的應用程序設置的方式旋轉風景。

這裏是我的GameConfig.h

#ifndef __GAME_CONFIG_H 
#define __GAME_CONFIG_H 

// 
// Supported Autorotations: 
//  None, 
//  UIViewController, 
//  CCDirector 
// 
#define kGameAutorotationNone 0 
#define kGameAutorotationCCDirector 1 
#define kGameAutorotationUIViewController 2 

// 
// Define here the type of autorotation that you want for your game 
// 
#define GAME_AUTOROTATION kGameAutorotationUIViewController 

#endif // __GAME_CONFIG_H 

而且我的AppDelegate的applicationDidFinishLaunching方法,

#if GAME_AUTOROTATION == kGameAutorotationUIViewController 
    //[director setDeviceOrientation:kCCDeviceOrientationPortrait]; 
    [director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft]; 
#else 
    // [director setDeviceOrientation:kCCDeviceOrientationPortrait]; 
    [director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft]; 
#endif 

而且RootController

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 

    return (UIInterfaceOrientationIsLandscape(interfaceOrientation)); 
    } 

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
    // 
    // Assuming that the main window has the size of the screen 
    // BUG: This won't work if the EAGLView is not fullscreen 
    /// 
    CGRect screenRect = [[UIScreen mainScreen] bounds]; 
    CGRect rect = CGRectZero; 


    if(toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)  
     rect = screenRect; 

    else if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) 
     rect.size = CGSizeMake(screenRect.size.height, screenRect.size.width); 

    CCDirector *director = [CCDirector sharedDirector]; 
    EAGLView *glView = [director openGLView]; 
    float contentScaleFactor = [director contentScaleFactor]; 

    if(contentScaleFactor != 1) { 
     rect.size.width *= contentScaleFactor; 
     rect.size.height *= contentScaleFactor; 
    } 
    glView.frame = rect; 
} 

在我的Info.plist中兼得山水的方向支持列表。

我在做什麼錯?

感謝

回答

1

嘗試將此行

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 

添加到您的applicationDidFinishLaunching:方法

+0

它沒有工作,仍然沒有旋轉可言。不過謝謝。 – Austin

+1

真的很奇怪。請確保將此代碼放置到applicationDidFinishLaunching方法中,然後放置斷點,確保它被調用,而不是將斷點放置到shouldAutorotateToInterfaceOrientation – Morion

+0

RootController中的shouldAutorotateToInterfaceOrientation方法未被調用,它會出現什麼情況? – Austin