0

我的游戏是基于 2D 汽车的游戏,有一个无限直的地图,我终于能够在其中添加一些随机障碍物。汽车只能在 3 个位置,一切正常。

关键是我最近注意到它没有响应,并试图通过在AppDelegate.cpp添加一行这样的行来使其响应

glview->setDesignResolutionSize(1024.0, 600.0, kResolutionFixedWidth);

我尝试使用kResolutionFixedWidthkResolutionFixedHeight和所有其他 5 个变量,你可以把它们放在那里,但我只有在屏幕上出现黑线,而且你可以想象到每一个屏幕故障 -.-'

我可以弄清楚我需要手动调整 TMXTiledMap 的大小,因为瓷砖的性质(我用 Tiled 做到了),但我不知道如何面对这个问题。

请注意,我目前正在为 1024x600 Android 设备开发,但我希望至少支持平板电脑和智能手机最常见的分辨率。

4

1 回答 1

0

您可能要使用 2 个解析策略。

如果您使用无边框,那么您应该看不到任何黑条,但引擎会裁剪您的设计分辨率,因此您不会希望将 UI 放在角落,或者您需要使用可见原点和可见大小来计算职位。

如果您使用Exact Fit,您应该将设计分辨率设置为设备的精确尺寸,然后您负责正确定位和缩放所有内容以避免失真。

如果您看到黑条,您将需要根据您的策略和设计分辨率选择来扩展您的艺术。

你读过这个维基页面吗? http://www.cocos2d-x.org/wiki/Multi_resolution_support

以下是我们为其中一款游戏所做的:

auto director = Director::getInstance();
auto glview = director->getOpenGLView();

float contentScaleFactor = 1.f;

// Set the design resolution
Size frameSize = glview->getFrameSize();
Size designSize = glview->getDesignResolutionSize();
CCLOG("defaults:");
CCLOG("framesize = {%f,%f}", frameSize.width, frameSize.height);
CCLOG("visibleSize = {%f,%f}", glview->getVisibleSize().width, glview->getVisibleSize().height);
CCLOG("designSize = {%f,%f}", designSize.width, designSize.height);
CCLOG("contentscalefactor = %f", director->getContentScaleFactor());

Vec2 origin = director->getVisibleOrigin();
CCLOG("visibleSize = %s", CStrFromSize(director->getVisibleSize()));
CCLOG("origin = {%f,%f}", origin.x, origin.y);

// Retina? 
contentScaleFactor = director->getContentScaleFactor();
float designWidth = frameSize.width / contentScaleFactor;
float designHeight = frameSize.height / contentScaleFactor;
CCLOG("contentScale = %f, designWidth/Height = {%f,%f}", contentScaleFactor, designWidth, designHeight);

glview->setDesignResolutionSize(designWidth, designHeight, ResolutionPolicy::EXACT_FIT);

// we designed the game for 480x320 (hence the divisors)
// used to scale full screen backgrounds
float fullWidthScaleFactor = designWidth/480.f;
// used to scale up most UI
float largeScaleFactor = floorf(designHeight/320.f);
// round to closest HALF step (1.0,1.5,2.0,2.5,3.0,etc)
// used for scaling UI where pixel art is affected by .1 scales
float largeScaleFactorExact = floorf(designHeight * 2.f / 320.f) * 0.5f;
// used to scale up UI that must be touchable (larger on high desnsity)
float largeScaleFactorUI = STROUND(designHeight / 320.f);

// this forces minimum of 1x scale (we should just not support these devices)
float scaleFitAll = designWidth > designHeight ? designHeight/320.f : designWidth/480.f;
if(largeScaleFactor < 1.f)
    largeScaleFactor = scaleFitAll;
if(largeScaleFactorExact < 1.f)
    largeScaleFactorExact = scaleFitAll;
if(largeScaleFactorUI < 1.f)
    largeScaleFactorUI = scaleFitAll;
于 2015-04-26T22:49:33.610 回答