首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使TMXTiledMap响应?

如何使TMXTiledMap响应?
EN

Stack Overflow用户
提问于 2015-04-25 09:36:27
回答 1查看 109关注 0票数 0

我的游戏是一个基于2D汽车的游戏,有一个直线无限的地图,在那里我终于能够添加一些随机的障碍。这辆车只有三个位置,一切都很好。

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

代码语言:javascript
复制
glview->setDesignResolutionSize(1024.0, 600.0, kResolutionFixedWidth);

我尝试使用kResolutionFixedWidth、kResolutionFixedHeight和所有其他你可以放在那里的5个变量,但我只能看到屏幕上的黑线和你能想象到的每一个屏幕故障

我可以知道,由于瓷砖的性质,我需要手动调整TMXTiledMap的大小(我是用瓷砖做的),但我不知道如何面对这个问题。

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-26 22:49:33

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

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

如果使用 Fit,则应该将设计分辨率设置为设备的精确大小,然后负责正确定位和缩放一切,以避免失真。

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

你读过这个维基页面了吗?support

以下是我们在其中一个游戏中所做的:

代码语言:javascript
复制
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;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29863477

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档