首先,对情况进行一些说明。
初始化平铺 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/