2

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?

Jens Piegsa
  • 7,399
  • 5
  • 58
  • 106
Alex
  • 59
  • 2
  • 7
  • We need to see your camera setup. My guess is that your camera viewport is not defined properly. – nEx.Software Jun 14 '13 at 16:44
  • My camera is: cam = new OrthographicCamera(MyWorld.CAMERA_WIDTH, MyWorld.CAMERA_HEIGHT); – Alex Jun 14 '13 at 17:01
  • And the values of `MyWorld.CAMERA_WIDTH` and `MyWorld.CAMERA_HEIGHT` are? – nEx.Software Jun 14 '13 at 17:04
  • As official site says, MyWorld.CAMERA_WIDTH, MyWorld.CAMERA_HEIGHT parses related to screen dimensions. In my case CAMERA_WIDTH = CAMERA_HEIGHT = 10. 10 is the count of cells in an row of tiledmap – Alex Jun 14 '13 at 17:04

1 Answers1

4

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);
nEx.Software
  • 6,782
  • 1
  • 26
  • 34
  • Thanks a lot. But what about Stage? Can I use "new MyWorld(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(),...)"? Or should I init square stage? MyWorld extends Stage – Alex Jun 14 '13 at 17:51
  • 1
    Your Stage can use the actual screen dimensions if you like. You would probably not want a square Stage either. – nEx.Software Jun 14 '13 at 18:09