cocos2d-x使用设备方向纵向和横向的最佳方法是什么

时间:2013-08-07 19:33:34

标签: cocos2d-x

我扫描了论坛以及测试示例,没有严格的答案 我如何支持游戏肖像和风景设备方向。在iOS上首先 有什么样的例子或来源或我可以看到和学习​​的东西 谢谢!

2 个答案:

答案 0 :(得分:1)

您可以参考:http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Device_Orientation

对于ios:在viewcontroller.m中

bool shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

// for Landscape

return UIInterfaceOrientationIsLandscape( interfaceOrientation );

// for Potrait

return UIInterfaceOrientationIsPotrait( interfaceOrientation );

}

如果是多个:

bool shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 

{

return UIInterfaceOrientationIsPortrait(interfaceOrientation)||UIInterfaceOrientationIsLandscape(interfaceOrientation) ;

}

根据您的方向缩放内容:

void didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation

CGSize s;
if (UIInterfaceOrientationIsLandscape(UIApplication.sharedApplication.statusBarOrientation))
{
s = CGSizeMake(std::max<float>(UIScreen.mainScreen.bounds.size.width,    UIScreen.mainScreen.bounds.size.height), 
                         std::min<float>(UIScreen.mainScreen.bounds.size.width,  UIScreen.mainScreen.bounds.size.height));
} 
else
{
s = CGSizeMake(std::min<float>(UIScreen.mainScreen.bounds.size.width,     UIScreen.mainScreen.bounds.size.height),  
                         std::max<float>(UIScreen.mainScreen.bounds.size.width, UIScreen.mainScreen.bounds.size.height));
}

CCDirector* director = cocos2d::CCDirector::sharedDirector();
director->enableRetinaDisplay(false);
director->getOpenGLView()->setFrameSize(s.width, s.height);
director->getOpenGLView()->setDesignResolutionSize(s.width, s.height, kResolutionShowAll);
director->enableRetinaDisplay(true);

答案 1 :(得分:0)

      bool AppDelegate::applicationDidFinishLaunching()
   {
    window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];


 window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
EAGLView *__glView = [EAGLView viewWithFrame: [window bounds]
                                 pixelFormat: kEAGLColorFormatRGBA8
                                 depthFormat: GL_DEPTH_COMPONENT16
                          preserveBackbuffer: NO
                                  sharegroup: nil
                               multiSampling: NO
                             numberOfSamples:0 ];

    // Use RootViewController manage EAGLView
     viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
    viewController.wantsFullScreenLayout = YES;
     viewController.view = __glView;
   } 


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