2011-04-26 92 views
1

我是cocos2d API的新手,並且注意到有幾種方法可以在模板中設置屏幕方向。我一直無法找出將我的方向設置爲LandscapeRight並在整個遊戲中保持這種方式的正確方法。如何更改方向以保持LandscapeRight?任何幫助表示讚賞。謝謝!Cocos2d - 設置設備/屏幕方向

回答

5

修改GameConfig.h從cocos2d的模板。

#define GAME_AUTOROTATION kGameAutorotationNone 
/* original code is kGameAutorotationUIViewController. */ 

並修改AppDelegate.m。

#if GAME_AUTOROTATION == kGameAutorotationUIViewController 
    [director setDeviceOrientation:kCCDeviceOrientationPortrait]; 
#else 
    [director setDeviceOrientation:kCCDeviceOrientationLandscapeRight]; 
    /* original code is "Left". */ 
#endif 
3

使用此行:

[[CCDirector sharedDirector] setDeviceOrientation:kkCCDeviceOrientationLandscapeRight]; 
1

在RootViewController.m,搜索線

return (UIInterfaceOrientationIsPortrait(interfaceOrientation)); 

改變它

return (UIInterfaceOrientationIsLandscape(interfaceOrientation)); 
8

這裏的答案與cocos2d的2.0改變,因爲現在CCDirector是一個視圖控制器iOS:

CCDirector不再支持devic e方向。所有自動旋轉和 設備方向現在由RootViewController處理。幸運的是, [[UIDevice currentDevice]方向]可用於代替 [[CCDirector sharedDirector] deviceOrientation]。枚舉是 相同,除了它們以UI而不是CC開頭。

強制特定取向是返回YES 僅在RootViewController的方法 shouldAutorotateToInterfaceOrientation所需取向的一個簡單的事情。

Choosing between Cocos2D v1.x & 2.x and Tips for updating to Cocos2D 2.0 at learn-cocos2d.com

-2

正確的答案 - 我花了一段時間來找到 - 在info.plist中,改變支持的接口方位值,項0和1項有4個可能的值,人像(頂級家居按鈕)等

+0

你的答案真的不是很清楚。 – 2013-01-02 05:38:36

0

如果添加shouldAutorotateToInterfaceOrientation並沒有解決你的問題

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return UIInterfaceOrientationIsLandscape(interfaceOrientation); 
} 

THEN 嘗試添加該林E要appDelegate.m

[window_ setRootViewController:navController_]; 

好運