【问题标题】:multi resolution support for all android devices所有安卓设备的多分辨率支持
【发布时间】:2015-07-01 01:32:50
【问题描述】:

我正在使用 cocos2d-x 将我的 cocos2d iPhone 游戏移植到 android。我现在面临屏幕分辨率的问题:我想在我的游戏中使用一个高分辨率图像,所有低于给定分辨率的屏幕都应该支持该图像。

我在论坛上阅读了多个分辨率的this nice tutorial。这真的很有帮助,但我没有实现我的解决方案。有设计分辨率和资源分辨率的资源比例因子的解释。

但是,就我而言,它可以按高度或按宽度进行缩放。不是我的图像的完美缩放。有人可以帮我解释一下为什么吗?

【问题讨论】:

    标签: cocos2d-x screen-resolution


    【解决方案1】:

    在 AppDeligate.cpp 中添加以下行

    设置 glview 后的 bool AppDelegate::applicationDidFinishLaunching()。

    CCEGLView *ev = CCEGLView::sharedOpenGLView();
    ev->setDesignResolutionSize(480, 320, kResolutionShowAll);
    

    480、320 是您为应用设计的分辨率。如果您想要纵向使用 320、480 代替。 如果手机纵横比与 480/320 纵横比不匹配,此解决方案将显示黑色边框。

    【讨论】:

      【解决方案2】:

      在 AppDelegate.cpp 中

      这是横向模式

      bool AppDelegate::applicationDidFinishLaunching()
      {
          // initialize director
      
          director = CCDirector::sharedDirector();
          EGLView  = CCEGLView::sharedOpenGLView();
      
          director->setOpenGLView(EGLView);
      
      
          CCSize screenSize = EGLView->getFrameSize();
          CCSize designSize = CCSizeMake(800, 480);
          EGLView->setDesignResolutionSize(designSize.width,designSize.height, kResolutionExactFit);
      
      
          if(screenSize.height > 480 && screenSize.height < 720 )
          {
      
              CCSize resourceSize = CCSizeMake(960, 540);
              director->setContentScaleFactor(resourceSize.height/screenSize.height);
              CCLog("Resolution Scale OF Karboon=%f",resourceSize.width/screenSize.width);
          }
      
      
          else if (screenSize.height >= 720 && screenSize.height < 800)
          {
      
              CCSize resourceSize = CCSizeMake(1280, 720);
              director->setContentScaleFactor(resourceSize.height/screenSize.height);
              CCLog("Resolution Scale OF NOTE=%f",resourceSize.width/screenSize.width);
      
          }
      
          else if(screenSize.height > 800)
          {
              CCSize resourceSize = CCSizeMake(1920, 1080);
              director->setContentScaleFactor(resourceSize.height/screenSize.height);
              CCLog("Resolution Scale OF Nexus=%f",resourceSize.width/screenSize.width);
      
          }
      
          else
          {
      
      
           director->setContentScaleFactor(1);
          CCLog("Resolution Scale OF S Advance=%f");
      
          }
      
      return true;
      
      }
      

      【讨论】:

      • 我以后定位东西时是否使用ContentScaleFactor?还是只在内部使用?
      【解决方案3】:

      这里有一些代码可以帮助您在“资源”文件夹中创建以下文件夹

      ipadhd 平板电脑 手机

      在 Appdelegate.cpp 中的 applicationdidfinishing 方法中使用此代码

          CCSize screenSize = pEGLView->getFrameSize();
              //set design size for iPad retina
              CCSize designSize = CCSize(2048, 1536);
      
              CCEGLView::sharedOpenGLView()->setDesignResolutionSize(designSize.width, designSize.height, kResolutionExactFit);
      
              if (screenSize.height > 768) {
                  CCFileUtils::sharedFileUtils()->setResourceDirectory("ipadhd");
              } else if (screenSize.height > 320) {
                  CCFileUtils::sharedFileUtils()->setResourceDirectory("ipad");
              } else {
                  CCFileUtils::sharedFileUtils()->setResourceDirectory("iphone");
              }
      pDirector->setContentScaleFactor(screenSize.height/designSize.height)
      

      希望这会有所帮助。将 iphone 的图像相应地放在 iphone 文件夹中,将 ipad 图像放在 ipad 文件夹中,将高清图像放在 ipadhd 文件夹中。 pDirector 这里是 CCDirector 变量。

      【讨论】:

        【解决方案4】:

        我遵循了这个很好的教程http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Multi_resolution_support

        这种方式对我有用。我使用了一张高分辨率图像

        AppDelegate.cpp

        typedef struct tagResource
        {
        cocos2d::CCSize size;
        char directory[100];
        }Resource;
        
        static Resource smallResource  =  { cocos2d::CCSizeMake(320,480),   "iphone" };
        static Resource mediumResource =  { cocos2d::CCSizeMake(768,1024),  "ipad"   };
        static Resource largeResource  =  { cocos2d::CCSizeMake(1536,2048), "ipadhd" };
        
        static cocos2d::CCSize designResolutionSize = cocos2d::CCSizeMake(640,1024);
        
        
        CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();
        
        CCSize frameSize = pDirector->getOpenGLView()->getFrameSize();
        
        
        pEGLView->setDesignResolutionSize( designResolutionSize.width, designResolutionSize.height,  kResolutionExactFit);
        
        
        if ((frameSize.height > mediumResource.size.height))
        { 
            pDirector->setContentScaleFactor(largeResource.size.height/designResolutionSize.height);
        
        
        }
        // if the frame's height is larger than the height of small resource size, select medium resource.
        else if ((frameSize.height > smallResource.size.height)) 
        
        { 
            pDirector->setContentScaleFactor(mediumResource.size.height/designResolutionSize.height);
        
        }
        // if the frame's height is smaller than the height of medium resource size, select small resource.
        else
        {
            pDirector->setContentScaleFactor(smallResource.size.height/designResolutionSize.height);
        
        }    
        
        CCDirector::sharedDirector()->setContentScaleFactor(1.f); 
        

        【讨论】:

        • 这是因为精确匹配政策。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-05-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-09-28
        • 1970-01-01
        • 2013-01-02
        相关资源
        最近更新 更多