У меня проблема с рисунком шрифта в LibGDX. Я хочу, чтобы изменить размер окна, и тексты будут читабельны. Ориентация приложения По умолчанию портрет, как это:LibGDX изменить размер шрифта шрифта
Я могу изменить его до начала альбомной в моем приложении, и все работает отлично:
Но Я хочу иметь возможность изменять размер приложения с портрета на пейзаж. . Но когда я пытаюсь это (например, от «пейзажа» к «портрету», тексты растягиваются
Мой код для визуализации и изменения размера функции (это просто код с нуля):.
?public void render() {
try
{
Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
//background draw
//_spriteBatch.begin();
//_spriteBatch.draw(background, 0, 0);
//_spriteBatch.end();
_spriteBatch.begin();
//sprite.draw(batch);
elapsedTime += Gdx.graphics.getDeltaTime();
_spriteBatch.draw(animation.getKeyFrame(elapsedTime, true), 0, 0);
_spriteBatch.end();
//content draw
_spriteBatch.begin();
if(!_isLandscape)
_spriteBatch.draw(img, 20, 210, 30, 45);
//NameDayDOM nameDayDOM = new NameDayDOM();
NameDaySAX nameDaySAX = new NameDaySAX();
name = nameDaySAX.getCurrentName(_serviceProvider.getAssetHandleResolver().resolve("namesday.xml").file());
//II _font.draw(_spriteBatch, "Happy Name Day, dear " + name, Gdx.graphics.getWidth()/7.0f, Gdx.graphics.getHeight()/2.0f);
if(!_isLandscape) {
BitmapFont.TextBounds bounds = _font40.getBounds("Happy Name Day");
_font40.draw(_spriteBatch, "Happy Name Day", (Gdx.graphics.getWidth()-bounds.width)/5.0f, Gdx.graphics.getHeight() - 120);
bounds = _font30.getBounds("dear" + name);
_font30.draw(_spriteBatch, "dear " + name, (Gdx.graphics.getWidth()-bounds.width)/3.2f, Gdx.graphics.getHeight() - 200);
bounds = _font23.getBounds("Post picture from this venue");
_font23.draw(_spriteBatch, "Post picture from this venue", (Gdx.graphics.getWidth()-bounds.width)/9.0f, Gdx.graphics.getHeight()/4.7f);
bounds = _font23.getBounds("and tell to world,");
_font23.draw(_spriteBatch, "and tell to world,", (Gdx.graphics.getWidth()-bounds.width)/7.0f, Gdx.graphics.getHeight()/5.5f);
bounds = _font23.getBounds("that you are enjoying your NameDay!");
_font23.draw(_spriteBatch, "that you are enjoying your NameDay!", (Gdx.graphics.getWidth()-bounds.width)/2.0f, Gdx.graphics.getHeight()/6.5f);
}else{
BitmapFont.TextBounds bounds = _font40.getBounds("Happy Name Day");
_font40.draw(_spriteBatch, "Happy Name Day", (Gdx.graphics.getWidth()-bounds.width)/14.0f, Gdx.graphics.getHeight()/1.7f);
bounds = _font30.getBounds("dear" + name);
_font30.draw(_spriteBatch, "dear " + name, (Gdx.graphics.getWidth()-bounds.width)/11.0f, Gdx.graphics.getHeight()/2.0f);
bounds = _font23.getBounds("Post picture from this venue");
_font23.draw(_spriteBatch, "Post picture from this venue", (Gdx.graphics.getWidth()-bounds.width)/14.0f, Gdx.graphics.getHeight()/4.7f);
bounds = _font23.getBounds("and tell to world,");
_font23.draw(_spriteBatch, "and tell to world,", (Gdx.graphics.getWidth()-bounds.width)/11.0f, Gdx.graphics.getHeight()/5.5f);
bounds = _font23.getBounds("that you are enjoying your NameDay!");
_font23.draw(_spriteBatch, "that you are enjoying your NameDay!", (Gdx.graphics.getWidth()-bounds.width)/9.0f, Gdx.graphics.getHeight()/6.5f);
}
}
catch(RuntimeException e)
{
_log.error("Exception on render: " + e);
_serviceProvider.getAppStatusListener().onStateChanged(AppState.Error);
}
finally {
_spriteBatch.end();
}
}
@Override
public void resize(int width , int height){
try {
System.out.println(width + " " + height);
if (height > width) {
_isLandscape = false;
} else {
_isLandscape = true;
}
}catch(Exception ex){
}
}
Что я делаю плохо Почему расположение текстов не меняется после изменения размера окна
Спасибо, мне кажется, что я должен использовать OrtographicCamera. Но я не уверен, каким образом. Пожалуйста, можете ли вы предоставить образец? Мне просто нужно рисовать текстовые строки после правильного изменения размера. –
У вас есть обновление? –
https://github.com/libgdx/libgdx/wiki/Orthographic-camera – Lestat