2

Currently I am using the following calculation to calculate the font scale resolution independent:

fontScale = ( Gdx.graphics.getDensity() / BaseDensity ) * (( (float)Gdx.graphics.getWidth() / (float)BaseResolutionWidth ) / (Gdx.graphics.getDensity() / BaseDensity) );

And I am using the following code to position my fonts relatively to one another:

font.draw(batch, glyphLayout, UniX(0.5f) - w * 0.5f, UniY(0.23f + 0.04f * scale) - h * 0.5f);

I am totally confused. The texts get displayed inside of each other on my 8 inch tablet, but they are alligned perfectly correct on my phone.

How should I correctly position this resolution independent?

Z0q
  • 1,689
  • 3
  • 28
  • 57
  • Not an answer to your problem but you're calculation for fontScale looks to cancel itself out. If you look at the alegbra doesn't it end up just being Gdx.graphics.getWidth / BaseResolutionWidth ? – Lionel Port Feb 05 '16 at 05:46
  • Yes it is. I managed to find the solution. – Z0q Feb 05 '16 at 12:49

1 Answers1

0

Since I am using my App strictly in portrait mode, I am using the following aspect ratio. This seems to work flawlessly cross my devices (phones & tablets).

aspectRatio = ( Gdx.graphics.getHeight() / Gdx.graphics.getWidth() );
fontScale = ( ( Gdx.graphics.getDensity() / BaseDensity ) * aspectRatio );
Z0q
  • 1,689
  • 3
  • 28
  • 57