LibGDX spritebatch 相对于屏幕大小调整大小
LibGDX spritebatch resize relative to screen size
这是我的问题。我正在尝试使用 LibGDX 渲染纹理,其位置和宽度相对于屏幕尺寸。这是我的做法:
public void render(float delta) {
Gdx.gl.glClearColor(1, 0, 1, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw(logo.getKeyFrame(frame), (Gdx.graphics.getWidth() / 2) - (logo.getKeyFrame(frame).getRegionWidth() / 2), Gdx.graphics.getHeight() - logo.getKeyFrame(frame).getRegionHeight());
batch.end();
stage.act(delta);
stage.draw();
}
@Override
public void resize(int width, int height) {
stage.getViewport().update(width, height, true);
}
问题是,当我尝试调整 window 的大小时,图像没有在应有的位置呈现。有没有什么办法解决这一问题?
谢谢:)
好的,我找到了解决问题的方法。我在调整大小方法中调用它
batch.getProjectionMatrix().setToOrtho2D(0, 0, width, height);
这是我的问题。我正在尝试使用 LibGDX 渲染纹理,其位置和宽度相对于屏幕尺寸。这是我的做法:
public void render(float delta) {
Gdx.gl.glClearColor(1, 0, 1, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw(logo.getKeyFrame(frame), (Gdx.graphics.getWidth() / 2) - (logo.getKeyFrame(frame).getRegionWidth() / 2), Gdx.graphics.getHeight() - logo.getKeyFrame(frame).getRegionHeight());
batch.end();
stage.act(delta);
stage.draw();
}
@Override
public void resize(int width, int height) {
stage.getViewport().update(width, height, true);
}
问题是,当我尝试调整 window 的大小时,图像没有在应有的位置呈现。有没有什么办法解决这一问题?
谢谢:)
好的,我找到了解决问题的方法。我在调整大小方法中调用它
batch.getProjectionMatrix().setToOrtho2D(0, 0, width, height);