cocos2dx应用程序的资产大小

时间:2014-02-22 20:41:39

标签: android ios iphone ipad cocos2d-x

按我的知识,使cocos2dx一个应用程序,我需要三套资源的iPad ipadhd iphone

从应用程序的一个示例中,我看到为了支持所有分辨率的设备,我朋友使用的资产大小(背景图像)是:

ipadhd:2272 X 1536

ipad:1136 X 768

iphone:568 X 384

这些尺寸适用于横向模式游戏。 这是我的问题: 1.为什么我们特别需要这些尺寸? 2.我试图做一个纵向模式游戏,我采取了同样的资产规模(但因为我在纵向模式下工作时,我把图像尺寸为1536 X 2272,768 X 1136和384 X 568)。但是,出于某种原因,当BG图像显示在模拟器/设备上时,它会被放大。我在这里附上屏幕截图。

原始图片: enter image description here

图像显示在模拟器中:

enter image description here

供参考,以下是设置设备分辨率大小和内容比例因子的代码:

#define TARGET_DESIGN_RESOLUTION_SIZE  DESIGN_RESOLUTION_480X320

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" };

#if (TARGET_DESIGN_RESOLUTION_SIZE == DESIGN_RESOLUTION_480X320)
static cocos2d::CCSize designResolutionSize = cocos2d::CCSizeMake(320, 480);
#elif (TARGET_DESIGN_RESOLUTION_SIZE == DESIGN_RESOLUTION_1024X768)
static cocos2d::CCSize designResolutionSize = cocos2d::CCSizeMake(768,1024);
#elif (TARGET_DESIGN_RESOLUTION_SIZE == DESIGN_RESOLUTION_2048X1536)
static cocos2d::CCSize designResolutionSize = cocos2d::CCSizeMake(1536,2048);
#elif (TARGET_DESIGN_RESOLUTION_SIZE == DESIGN_RESOLUTION_NONE)
static cocos2d::CCSize designResolutionSize = cocos2d::CCSizeMake(320, 480);
#else
#error unknown target design resolution!
#endif


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

pDirector->setOpenGLView(pEGLView);

// Set the design resolution
pEGLView->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height,kResolutionNoBorder);
CCSize frameSize = pEGLView->getFrameSize();

std::vector<std::string> resDirOrders;

// if the frame's height is larger than the height of medium resource size, select large resource.
if (frameSize.width > mediumResource.size.width)
{
    resDirOrders.push_back(largeResource.directory);
    pDirector->setContentScaleFactor(largeResource.size.width/designResolutionSize.width);
}
// if the frame's height is larger than the height of small resource size, select medium resource.
else if (frameSize.width > smallResource.size.width)
{
    resDirOrders.push_back(mediumResource.directory);
    pDirector->setContentScaleFactor(mediumResource.size.width/designResolutionSize.width);

}
// if the frame's height is smaller than the height of medium resource size, select small resource.
else
{
    resDirOrders.push_back(smallResource.directory);
    pDirector->setContentScaleFactor(smallResource.size.width/designResolutionSize.width);
}
CCFileUtils::sharedFileUtils()->setSearchPaths(resDirOrders);

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

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

// create a scene. it's an autorelease object
CCScene *pScene = GameLayer::scene();

// run
pDirector->runWithScene(pScene);

return true;
}

1 个答案:

答案 0 :(得分:3)

实际上,原因是您的资源(资产)大小(分辨率)与您设置的设计分辨率不匹配。您的资产具有不同的宽高比,并且设计分辨率具有不同的宽高比。

我从未真正在我的游戏中使用contentScaleFactor。如果所有资产具有相同的比例,只需将设计分辨率设置为相同的资产分辨率即可。如果您使用kResolutionExactFit策略,Cocos2d-x会自动重新调整到设备屏幕。

我认为你应该阅读Detailed explanation of cocos2d-x multi-resolution support。这是一篇写得很好的文章。