4
\$\begingroup\$

I'm a noob when it comes to programming Java apps, so I'm trying to make a very simple platformer game.

All is running very well on the desktop project, but when I put the game on my Xperia, a strange thing happens:

Screenshots of game in different aspect ratios

I have an elevated floor and other tiles, and on phone screen, this all appears squashed: the tiles and the elevated floor display in a lower position than the desktop version, which is an ugly problem. Resizing the window on PC, it all runs and resizes correctly, maintaining the aspect ratio.

The second image is the regular window, and the last is at the minimum size window, but the aspect ratio is the same as on the larger window. If I stretched out the window, everything is stretched, but the upper floor and the sprite maintains the same distance. I don't understand what is happening on the mobile version.

I'm using Tiled to draw the map, and in my code I use OrthogonalTiledMapRenderer and TiledMap, with an OrthographicCamera. I "zoom" with camera.setToOrtho to crop to a part of the map.

The figure is a Sprite in then code. The floor and the "door" are layers in Tiled (floor and doors). I configured them as 16x16 tiles, but configuring them as 32x32 or more gives the same result.

I tried all viewports and still have not solved the problem. A potential solution I can think of is to cut off the top part when resizing, but I don't know how to do it!

\$\endgroup\$
1
  • \$\begingroup\$ Do you call mapRenderer.setView(camera); or mapRenderer.setView(projectionMatrix, startX, startY, endx, endY); whenever you change your camera position? \$\endgroup\$ Jul 18, 2016 at 21:43

1 Answer 1

1
\$\begingroup\$

The book uses a "different" technique to resize objects on game, not a Viewport. Well, the solution (working at the moment) has been:

  1. A fixed size to the sprite (character.setsize(3,5)).
  2. Apply a ScreenViewport().

And that's all.

I found this asking a question on libgdx IRC channel, and a user said to try with different screen configurations in code, changing Gdx.graphics.setWidth() and setHeight() to screen values of the phone, and I tried that on PC version, and, after a lot of tries, it worked!

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .