2

我浏览了论坛和测试示例,但没有严格回答我如何支持游戏纵向和横向设备方向的问题。首先在 iOS 上是否有任何示例或来源或我可以看到和学习​​的东西谢谢!

4

2 回答 2

1

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

对于 ios:在 viewcontroller.m

bool shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

// 用于风景

return UIInterfaceOrientationIsLandscape( interfaceOrientation );

// 对于肖像

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);
于 2013-08-08T09:32:13.560 回答
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 );
   }
于 2013-08-08T14:25:58.443 回答