문제

First of all, some explanation of situation.

Init tiled map code:

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

Rendering code:

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

The problem. I have square map and non-square screen. Map fills whole screen. Because of that map scales incorrectly (32x32 cells transform to 32x40 cells according to X and Y scaling of screen). How can I render map without filling whole screen?

도움이 되었습니까?

해결책

Based on the comments on the question...

You are using a square camera on a non-square screen and ignoring the aspect ratio. To take into account the aspect ratio, do something like this:

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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top