2011-05-13 29 views
5

我正在構建一個應該是肖像模式的cocos2d遊戲。我將RootViewController.m更改爲縱向模式,並且在模擬器和iPad上都可以正常工作。但是,當我在iPhone上運行遊戲時,它默認回到橫向模式。Cocos2d肖像模式不能在iPhone上工作

有關如何解決此問題的任何想法?

謝謝。

回答

7

我有一個更好的解決方案,將工作100%:

全部替換,這是在RootViewController.m/ shouldAutorotateToInterfaceOrientation方法有以下東西:

回報(UIInterfaceOrientationIsPortrait(interfaceOrientation));

而且如果我想在運行時改變方向/切換場景:

[CCDirector sharedDirector] setDeviceOrientation:CCDeviceOrientationLandscapeLeft]。

需要注意的是自動旋轉現在是不再支持

+0

嘿亞歷山大,我試過了,但顛倒模式也啓用。所以我如何才能啓用肖像模式?您使用的是Cocos2D 1.x還是2.0測試版,您是否使用 – OMGPOP 2012-01-27 10:20:27

+0

? – 2012-01-29 22:54:54

0

的RootViewController的內部返回false從以下方法:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 

    return false; 

    // other code... 

} 
0

在RootViewController.m

return (UIInterfaceOrientationIsLandscape(interfaceOrientation)); 

改變這一行

return (UIInterfaceOrientationIsPortrait(interfaceOrientation)); 
+0

是的,這正是我做了。它可以在模擬器和我的iPad上正常工作,但由於某種原因,它不適用於我的iPhone。 – Nick 2011-05-13 15:45:36

+0

,但現在只適用於肖像模式,我希望兩個方向 – 2012-06-19 09:04:55

1

在GameConfig.h:

使用主任自轉

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

,而不是

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

和在AppDelegate.m

- (void) applicationDidFinishLaunching:(UIApplication*)application 
{ 
... 
[director setDeviceOrientation:kCCDeviceOrientationPortrait]; 
0
在GameConfig.h

For 1st and 2nd generation devices, value is set to kGameAutorotationNone, change it to kGameAutorotationUIViewController. 

// ARMv6 (1st and 2nd generation devices): Don't rotate. It is very expensive 
#elif __arm__ 
#define GAME_AUTOROTATION kGameAutorotationNone 
相關問題