【问题标题】:cocos2d-x What is the best way to use device orientation portrait and landscapecocos2d-x 使用设备方向纵向和横向的最佳方式是什么
【发布时间】:2013-08-07 19:33:33
【问题描述】:

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

【问题讨论】:

  • 你到底想要什么...请简要说明
  • 我想了解当用户将其设备从纵向旋转到横向或从横向纵向旋转时是否有图案或需要编码的东西,屏幕上的所有图层和精灵如何保持纵横比以及如何改变位置

标签: cocos2d-x


【解决方案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);

【讨论】:

  • 是的,我知道这一点,但我需要检查当用户旋转其设备时动态的解决方案,并且我需要旋转我所有的图层和精灵坐标或其他东西......
  • @user63898 .. 我明白 .. 因为你必须根据你的方向缩放你的内容 .. 你可以通过 ContentScaleFactor 和 designResolutionsize 实现这一点 .. 。你可以看到这个cocos2d-x.org/projects/cocos2d-x/wiki/Multi_resolution_support ..
  • @user63898 检查我的 que & ans 。 stackoverflow.com/questions/17948382/…..... 这可能会有所帮助..
  • 感谢重播,cocos2d-x的答题不太好,想知道为什么要满大师
  • shouldAutorotateToInterfaceOrientation 已弃用
【解决方案2】:
      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 );
   }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-16
    • 2013-10-08
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    相关资源
    最近更新 更多