简体   繁体   English

如何使TMXTiledMap响应?

[英]How to make TMXTiledMap responsive?

My game is a 2D car-based one, with a straight infinite map where I've finally been able to add some random obstacles. 我的游戏是基于2D汽车的游戏,具有直线无限地图,我终于能够在其中添加一些随机障碍。 There are only 3 positions the car can be at, and everything is working fine. 汽车只能处于3个位置,并且一切正常。

The point is that I've recently noticed that it is not responsive, and tried to make it responsive by adding a line like these one to the AppDelegate.cpp : 关键是我最近注意到它没有响应,并通过在AppDelegate.cpp中添加如下一行来使其响应

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

I've tried to use kResolutionFixedWidth , kResolutionFixedHeight and all others 5 variables you can put there, but I only got black lines along the screen and every single screen breakdown you can imagine -.-' 我试图使用kResolutionFixedWidthkResolutionFixedHeight和其他所有5个变量可以放置在其中,但是我只在屏幕上看到黑线,并且可以想象每一个屏幕故障-.-'

I can figure out I need to resize my TMXTiledMap manually because of the nature of tiles (I did it with Tiled), but I don't know how to face this problem. 由于磁贴的性质,我可以确定我需要手动调整TMXTiledMap的大小(我使用Tiled做到了),但是我不知道如何面对这个问题。

Note that I'm currently developing for a 1024x600 Android device but I would want to support at least the most common resolutions for both tablets and smartphones. 请注意,我目前正在开发1024x600的Android设备,但我希望至少支持平板电脑和智能手机的最常用分辨率。

There are probably 2 resolution policies you want to use. 您可能要使用2种分辨率策略。

If you use No Border then you shouldn't see any black bars, but the engine will crop your design resolution so you won't want to put UI in the corners, or you'll want to use Visible Origin and Visible Size to calculate positions. 如果您使用“ 无边界”,那么您应该不会看到任何黑条,但是引擎会裁切您的设计分辨率,因此您不想将UI放在角落,或者希望使用“可见原点”和“可见大小”进行计算职位。

If you use Exact Fit you should set the design resolution to the devices exact size, and then you're responsible for positioning and scaling everything correctly to avoid distortion. 如果使用精确匹配 ,则应将设计分辨率设置为设备的确切尺寸,然后负责正确放置和缩放所有内容,以免发生变形。

You will need to scale your art depending on your policy and design resolution choices if you are seeing black bars. 如果您看到黑条,则需要根据策略和设计分辨率选择来缩放艺术作品。

Have you read through this wiki page? 您已阅读此Wiki页面吗? http://www.cocos2d-x.org/wiki/Multi_resolution_support http://www.cocos2d-x.org/wiki/Multi_resolution_support

Here's what we do for one of our games: 这是我们为其中一款游戏所做的工作:

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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM