Thursday, July 30, 2015

libgdx - Why does resizing my game window move and distort my rendering?


I'm starting to make a game, and the first screen I've made is a very simple loading screen with some centered text.


On starting it up, the text is nicely centered: enter image description here


Then I resize the window, and I get: enter image description here


Why is it stretched? And why has it moved? Looking at my code it looks like everything should be perfectly centered:


public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0.2f, 1);

Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

if (Assets.manager.update()) {
// Eventually change to a main menu or something
}

String text = "Loading " + Math.round(Assets.manager.getProgress()) + "%";

BitmapFont.TextBounds bounds = fnt.getBounds(text);


batch.begin();
fnt.draw(batch, text, (Gdx.graphics.getWidth()/2)-(bounds.width/2), (Gdx.graphics.getHeight()/2)-(bounds.height/2));
batch.end();
}


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...