2011-04-26 106 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_]; 

好运