4

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

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

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

4

4 回答 4

3

在 AppDeligate.cpp 中将以下行添加到

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

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

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

于 2013-07-31T03:10:26.873 回答
1

在 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;

}
于 2014-01-04T18:16:06.700 回答
0

我跟着这个很好的教程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); 
于 2013-08-07T07:52:12.757 回答
0

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

ipadhd ipad iphone

在应用程序完成方法的 Appdelegate.cpp 中使用此代码

    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 文件夹中,将 ipad 图像放在 ipad 文件夹中,将高清图像放在 ipadhd 文件夹中。pDirector 这里是 CCDirector 变量。

于 2013-07-31T08:03:20.753 回答