2014-02-22 49 views
2

按我的知识,使cocos2dx一个应用程序,我需要三套资源的ipad的,ipadhdiphone资产尺寸cocos2dx应用

从应用的一个例子,我看到了,为了支持所有分辨率的设备,资产规模(背景图像),我的朋友已经使用了:

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

回答

3

其实,原因是因为你的资源(资产)的大小(分解离子)与您设定的设计分辨率不匹配。您的资产具有不同的长宽比,设计分辨率具有不同的长宽比。

我从来没有真正在我的游戏中使用contentScaleFactor。如果所有资产规模相同,只需将设计分辨率设置为资产的相同分辨率即可。如果您使用kResolutionExactFit策略,Cocos2d-x会自动重新缩放到设备屏幕。我想你应该阅读Detailed explanation of cocos2d-x multi-resolution support。这是一篇写得很好的文章。

+0

我正在使用kResolutionNoBorder策略。 但您已准备好了解资产大小问题。我现在使用的是标准视网膜和非视网膜大小的资产,而且工作效果很好。欢呼 – IamRKhanna

+0

使用kResolutionExactFit,事情会变得更好,但我会将其留给您的选择。如果此答案解决了您的问题,请将其标记为已接受,以便可以帮助其他人。 – Wajahat