android - 如何纠正 libgdx 中平铺 map 渲染的纵横比?

标签 android libgdx tiled

首先,对情况进行一些说明。

初始化平铺 map 代码:

map = new TmxMapLoader().load("maps/map.tmx");
mapRenderer = new OrthogonalTiledMapRenderer(map, 1f / 32f);

渲染代码:

mapRenderer.setView(cam);
mapRenderer.render();

问题。我有方形 map 和非方形屏幕。 map 填满整个屏幕。由于该 map 比例不正确(根据屏幕的 X 和 Y 缩放,32x32 单元格转换为 32x40 单元格)。如何在不填满整个屏幕的情况下渲染 map ?

最佳答案

根据对问题的评论...

您在非方形屏幕上使用方形相机并忽略宽高比。要考虑纵横比,请执行以下操作:

float w = Gdx.graphics.getWidth();
float h = Gdx.graphics.getHeight();

MyWorld.CAMERA_HEIGHT = 10;  // Fill the height of the screen
MyWorld.CAMERA_WIDTH  = 10 * (w / h); // Account for the aspect ratio

camera = new OrthographicCamera(MyWorld.CAMERA_WIDTH, MyWorld.CAMERA_HEIGHT);

关于android - 如何纠正 libgdx 中平铺 map 渲染的纵横比?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17113088/

相关文章:

android - 如何处理与 UI 元素的全屏触摸交互

android - 关于Android列表项设计的建议

android - 微调器 : get state or get notified when opens

android - ScaleTo 在 Libgdx 中不工作

c# - 构建项目时出错 : Error building Player because scripts have compile errors in the editor

c++ - cocos2dx 将值转换为属性字符串

android - 结合列表和非 ListView 的最佳实践,例如市场

java - 中心 libgdx 阶段对象

java - Intellij Idea lib文件夹导出

ios - 垂直间隙出现在 iOS 应用程序上,但不出现在 Unity 编辑器上