【问题标题】:How to make TMXTiledMap responsive?如何使 TMXTiledMap 响应?
【发布时间】:2015-04-25 09:36:27
【问题描述】:

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

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

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

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

由于图块的性质,我知道我需要手动调整 TMXTiledMap 的大小(我是用 Tiled 完成的),但我不知道如何面对这个问题。

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

【问题讨论】:

  • 我的问题有什么问题?礼貌在这里有问题吗?

标签: android opengl-es cocos2d-x resolution tiled


【解决方案1】:

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

如果您使用无边框,那么您应该不会看到任何黑条,但引擎会裁剪您的设计分辨率,因此您不会希望将 UI 放在角落,否则您会想使用 Visible Origin 和 Visible Size 来计算位置。

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

如果您看到黑条,则需要根据您的政策和设计分辨率选择来缩放您的艺术作品。

您是否已阅读此 wiki 页面? 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;

【讨论】:

  • 是的,我阅读了 wiki 页面并没有达到任何目的,这就是我要求这样做的原因。几天后,当我完成这个 Sprint 时,我会试试你所说的。我明白了这一点,我想这就是解决方案。感谢您的回答
猜你喜欢
  • 2013-01-28
  • 2021-07-03
  • 1970-01-01
  • 2012-12-11
  • 1970-01-01
  • 2023-02-05
  • 2019-02-19
  • 2016-02-09
  • 2014-06-05
相关资源
最近更新 更多