Cocos2d - 设置设备/屏幕方向

Mic*_*ael 1 iphone cocos2d-iphone

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

Wis*_*uck 8

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

CCDirector不再支持设备方向.所有自动旋转和设备方向现在都由RootViewController处理.幸运的是,[[UIDevice currentDevice] orientation]可以代替[[CCDirector sharedDirector] deviceOrientation].枚举是相同的,除了它们以UI而不是CC开头.

强制特定方向是一个简单的事情,只能在RootViewController方法shouldAutorotateToInterfaceOrientation中将YES返回到所需的方向.

在cocos2D v1.x和2.x之间选择以及在learn-cocos2d.com上更新到Cocos2D 2.0的提示


Kaz*_*oto 5

从cocos2d模板修改GameConfig.h.

#define GAME_AUTOROTATION kGameAutorotationNone
/* original code is kGameAutorotationUIViewController. */
Run Code Online (Sandbox Code Playgroud)

并修改AppDelegate.m.

#if GAME_AUTOROTATION == kGameAutorotationUIViewController
    [director setDeviceOrientation:kCCDeviceOrientationPortrait];
#else
    [director setDeviceOrientation:kCCDeviceOrientationLandscapeRight];
    /* original code is "Left". */
#endif
Run Code Online (Sandbox Code Playgroud)