【发布时间】:2014-02-22 20:41:39
【问题描述】:
据我所知,在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 图像显示在模拟器/设备上时,它会被放大。我在这里附上屏幕截图。
原图:
模拟器中显示的图像:
供参考,这里是设置设备分辨率大小和内容比例因子的代码:
#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;
}
【问题讨论】:
标签: android ios iphone ipad cocos2d-x