Reputation: 113
What I want to have is the Bitmap Font to change in size accordingly when changing screen sizes. What I mean is on my computer, the font appears rather large, but on my phone, it is a little font that is harder to read. I could change the size, but I want it to look similar on all screens, instead of having it large on one screen and smaller on another. Here is my code to see what I have to work with:
public void render() {
//score system
scoreFont.setColor(1.0f, 1.0f, 1.0f, 1.0f);
scoreBatch.begin();
scoreFont.draw(scoreBatch, Long.toString(getScore()), 10, Gdx.graphics.getHeight() - 10);
scoreFont.setScale(3, 3);
scoreBatch.end();
}
public void resize(int width, int height) {
camera.viewportWidth = 450;
camera.viewportHeight = 250;
camera.update();
stage.setViewport(450, 250, true);
stage.getCamera().translate(-stage.getGutterWidth(), -stage.getGutterHeight(), 0);
}
Upvotes: 2
Views: 7959
Reputation: 1108
Think of it this way, you always want to have the same ratio.
For example:
500/3 = 450/x
x is the new size of your text. So you have to do some cross multiplying.
500x = 1350
1350÷500 = x
So now to do this programmatically.
public void resizeText(float width, float currentSize, float currentWidth){
//currentWidth/currentSize = width/x
a = width * currentSize;//450 * 3 in example above
b = a/currentWidth;
return b;//returns the x or the new size that your text should be
}
Also you said that it needs to change depending on of the size is over a certain amount.
So here's a little thing I've devised
ApplicationType appType = Gdx.app.getType();
if (appType == ApplicationType.Android || appType == ApplicationType.iOS) {
screenFont.setScale(your number)
} else { screen font.setScale(otherNum)} //if its a desktop
Upvotes: 2