我已经使用cocos2dx为具有大小 480 * 320 的设备制作了Android构建,并且它可以正常工作,但当我在另一个Android设备中放入具有大小 640 * 480 缩放问题发生了....

我正在使用以下代码自动重新大小,但它不起作用:

AppDelegate app;
CCEGLView& eglView = CCEGLView::sharedOpenGLView();
eglView.setViewName("Hello Lua");
eglView.setFrameSize(480, 320);

// set the design resolution screen size, if you want to use Design Resoulution scaled to current screen, please uncomment next line.
// eglView.setDesignResolutionSize(480, 320);
.

有帮助吗?

解决方案

首先,您粘贴的代码来自main.cpp文件,当您为Android或Windows手机或iOS编译应用程序时不播放一部分。该文件适用于Win32项目。

现在, 对于应用自动缩放,AppDelegate.cpp中的函数应设置设计分辨率以及策略。我使用ExactFit政策,因为它延长了应用程序来填充整个屏幕区域,它适用于Android,Windows,iOS所有(我开发了应用程序和测试):

bool AppDelegate::applicationDidFinishLaunching()
{
    // initialize director
    CCDirector *pDirector = CCDirector::sharedDirector();
    pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
    // turn on display FPS
    CCEGLView::sharedOpenGLView()->setDesignResolutionSize(1200, 720, kResolutionExactFit);
    pDirector->setDisplayStats(false);

    pDirector->setAnimationInterval(1.0 / 60);

    CCScene *pScene = HelloWorld::scene();

    pDirector->runWithScene(pScene);
    return true;
}
.

你还应该看看对多分辨率支持的详细说明更好地理解。

其他提示

如果你没有意识到伸展的外观,那么这样做。它将适用于所有设备。

pDirector->setOpenGLView(pEGLView);

CCSize frameSize = pDirector->getOpenGLView()->getFrameSize();
CCLog("%.2f and %.2f is Frame size\n",frameSize.width,frameSize.height);
pEGLView->setDesignResolutionSize(960, 640, kResolutionExactFit);
.

注意:上面的设置是横向的,如果您需要它才能拍照只是反转peglview-> setDesignResolution的值(640,960,kresolutionexactfit)

这里了解的是,您将在640x960和Kresolutionexactfit的坐标上设计的所有内容都将把东西固定为适合屏幕。要更轻松地执行此操作,您应该使用Coocos Builder http://cocosbuilder.com/ 并在自定义布局上设计所有内容640x960

我推荐了双分辨率(640x960),因为这种方式不会降低质量,并将在所有类型的设备上看起来清脆,但是拉伸外观的缺点将在那里。

如果要以多种方式考虑多个分辨率,那么您必须制作多个图形和多个布局,再次Cocos Builder将是最好的方法。

i.e for iPhone 5将是差异,对于iPad和标准480x320将是差异。为此,您可以在帧大小上进行检查以选择相应的视图。

CCSize frameSize = pDirector->getOpenGLView()->getFrameSize();
.

你应该在每一面都有一些切割。这是完成的,因为是兼容模式如何匹配480x320的屏幕Res的最佳方式。其他选项正在留下高度的部分或延伸图像(以某种性能(?)的成本)。

首先可以轻松完成一个CCEGLView::create方法,可以在Scalefactor公式中将min更改为max及其完成,但这可能会巧妙地串链:p

bool AppDelegate::applicationDidFinishLaunching()
{
    // initialize director
    CCDirector* pDirector = CCDirector::sharedDirector();
    CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();

    pDirector->setOpenGLView(pEGLView);

    // Set the design resolution
    // iPad size
    CCPoint res = CCPoint(768,1024);
    pEGLView->setDesignResolutionSize(res.x,
                                      res.y,
                                      kResolutionNoBorder);
  .....
}
.

检查分辨率并对屏幕尺寸进行更改: (此示例是肖像游戏)

typedef struct tagResource
{
   cocos2d::Size size;
   char directory[100];
}Resource;

std::vector<std::string> searchPath;
static Resource designResource =  { cocos2d::Size(768, 1024),  "ipad"};
static Resource smallResource  =  { cocos2d::Size(320, 480),   "iphone"};
static Resource galax7Resource =  { cocos2d::Size(600, 1024),  "gt_7p"  };
static Resource mediumResource =  { cocos2d::Size(768, 1024),  "ipad"};
static Resource galax10Resource =  { cocos2d::Size(800, 1280),  "gt_10p"};
static Resource fullHDResource  =  { cocos2d::Size(1080, 1920), "fullhd"};
static Resource largeResource  =  { cocos2d::Size(1536, 2048), "ipadhd"};
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
glview->setDesignResolutionSize(designResource.size.width, designResource.size.height, ResolutionPolicy::EXACT_FIT);
Size frameSize = glview->getFrameSize();
Resource realResource;
// if the frame's height is larger than the height of medium size.
if (frameSize.height > fullHDResource.size.height) {
    realResource = largeResource;
    CCLOG("largeResource");
} else if (frameSize.height > galax10Resource.size.height) {
    realResource = fullHDResource;
    CCLOG("fullHDResource");
} else if (frameSize.height > mediumResource.size.height) {
    realResource = galax10Resource;
    CCLOG("galax10Resource");
} else if (frameSize.height > smallResource.size.height) {
    if(frameSize.width > galax7Resource.size.width){
        realResource = mediumResource;
        CCLOG("mediumResource");
    }else {
        realResource = galax7Resource;
        CCLOG("galax7Resource");
    }
} else {
    realResource = smallResource;
    CCLOG("smallResource");
}
director->setContentScaleFactor(MIN(realResource.size.height/designResource.size.height, realResource.size.width/designResource.size.width));
searchPath.push_back(realResource.directory);
    auto fileUtils = FileUtils::getInstance();
fileUtils->setSearchPaths(searchPath);
.

我正在使用cocos2dx v3,但v2的想法是相同的。

我在我的3Match游戏中使用了以下解决方案策略 在appdelegate.cpp

#define IS_LANDSCAPE

#ifdef IS_LANDSCAPE
static cocos2d::Size designResolutionSize = cocos2d::Size(1136,768);
#else
static cocos2d::Size designResolutionSize = cocos2d::Size(768,1136);
#endif

//==========================
bool AppDelegate::applicationDidFinishLaunching() {

    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
        glview = GLViewImpl::create("My Game");
        director->setOpenGLView(glview);
    }

    // turn on display FPS
    director->setDisplayStats(false);

    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0 / 60);

    // Set the design resolution
     glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::NO_BORDER);

    register_all_packages();

    // create a scene. it's an autorelease object
    auto scene =loading::createScene();

    // run
    director->runWithScene(scene);

    return true;
}
.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top