2012-01-14 38 views
2

我使用默認的cocos2d模板稍作修改的基本代碼。
我的遊戲只在左側或右側播放 - 沒有人像。

當遊戲啓動時,它啓動正確,然後翻轉顛倒,然後再次翻轉。
我翻看了關於該問題的幾篇文章,似乎無法將我的手指放在讓界面翻轉而不移動設備的東西上。
感謝任何幫助!

我有以下相關代碼:

RootViewController.m:
Cocos2d遊戲的方向切換左 - >右 - >左啓動後直接

#if GAME_AUTOROTATION == kGameAutorotationUIViewController 

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
    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; 
} 
#endif 

的AppDelegate:

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

GameConfig.h:

#define kGameAutorotationNone 0 
#define kGameAutorotationCCDirector 1 
#define kGameAutorotationUIViewController 2 

#if defined(__ARM_NEON__) || TARGET_IPHONE_SIMULATOR 
#define GAME_AUTOROTATION kGameAutorotationUIViewController 

#elif __arm__ 
#define GAME_AUTOROTATION kGameAutorotationNone 
+0

請重新發布不含HTML格式的代碼,目前它無法讀取。 – LearnCocos2D 2012-01-14 15:22:54

回答

3

我有同樣的問題今天,它似乎歸結爲ord呃在我的應用程序plist中支持的方向。該應用程序將在橫向左側,右側翻轉,然後再快速翻轉到左側。

我在「摘要」選項卡(配置支持的方向,應用程序圖標,啓動圖像等)中進入我的項目屬性,並取消選擇所有支持的方向。

然後按順序再次勾選它們(風景右側,風景左側) - 並在「信息」選項卡中驗證它們按陣列中的順序排列,位於「支持的接口方向」部分下。

項目0 - 風景(右home鍵) 項目1 - 景觀(左home鍵)

沒有因爲這個問題,希望這有助於。

+0

謝謝你!你不知道我用這個愚蠢的東西丟了多少時間! – Lio 2012-10-19 14:13:41