Cocos2d - 设置设备/屏幕方向

时间:2011-04-26 15:32:30

标签: iphone cocos2d-iphone

我是cocos2d API的新手,并注意到有几种方法可以在模板中设置屏幕方向。我无法弄清楚将方向设置为LandscapeRight的正确方法,并在整个游戏中保持这种方式。如何更改方向以保持LandscapeRight?任何帮助表示赞赏。谢谢!

6 个答案:

答案 0 :(得分:8)

这里的答案已经改变了cocos2d 2.0,因为CCDirector现在是iOS上的ViewController:

  

CCDirector不再支持设备方向。所有自转和   设备方向现在由RootViewController处理。幸好,   可以使用[[UIDevice currentDevice] orientation]代替   [[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

答案 1 :(得分:5)

从cocos2d模板修改GameConfig.h。

#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

答案 2 :(得分:3)

使用此行:

[[CCDirector sharedDirector] setDeviceOrientation:kkCCDeviceOrientationLandscapeRight];

答案 3 :(得分:1)

在RootViewController.m中,搜索行

return ( UIInterfaceOrientationIsPortrait(interfaceOrientation ));

将其更改为

return ( UIInterfaceOrientationIsLandscape(interfaceOrientation ));

答案 4 :(得分:0)

如果你添加了shouldAutorotateToInterfaceOrientation而没有解决你的问题

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

THEN 尝试将此行添加到appDelegate.m

[window_ setRootViewController:navController_];

祝你好运

答案 5 :(得分:-2)

正确答案 - 花了一些时间才找到 - 在info.plist中,更改支持的界面方向值,项目0和项目1有4个可能的值,纵向(顶部主页按钮)等。

相关问题