gpt4 book ai didi

android - cocos2dx 应用程序的 Assets 大小

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:06:23 24 4
gpt4 key购买 nike

据我所知,要在cocos2dx中做一个应用,我需要三套资源ipadipadhdiphone

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

硬盘驱动器:2272 X 1536

iPad: 1136 X 768

苹果手机:568 X 384

这些尺寸适用于横向模式游戏。这是我的问题:1. 为什么我们特别需要这些尺寸?2. 我正在尝试制作一款采用相同 Assets 大小的纵向模式游戏(但由于我在纵向模式下工作,因此我将图像尺寸设为 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;
}

最佳答案

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

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

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

关于android - cocos2dx 应用程序的 Assets 大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21960257/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com