[英]libGDX - FitViewport doesnt scale well the stage
我想做的是在不更改寬高比的情況下,在屏幕上盡可能多地顯示虛擬世界,並在屏幕上盡可能縮放該世界,FitViewport似乎是最佳選擇。 這就是我在舞台上初始化視口的方式。
public class PlayStage extends Stage{
public static final int WIDTH = 480;
public static final int HEIGHT = 800;
private final Vector2 gravity = new Vector2(0.f, -9.8f);
private World physWorld;
public PlayStage(){
super();
OrthographicCamera camera = new OrthographicCamera();
camera.setToOrtho(false, WIDTH, HEIGHT);
setViewport(new FitViewport(WIDTH, HEIGHT, camera));
physWorld = new World(gravity, false);
Gdx.input.setInputProcessor(this);
Ball ball = new Ball(physWorld);
setKeyboardFocus(ball);
addActor(ball);
}
@Override
public void draw() {
super.draw();
}
@Override
public void act(float delta) {
super.act(delta);
physWorld.step(delta, 10, 5);
}
@Override
public void dispose() {
super.dispose();
physWorld.dispose();
}}
這就是精靈在渲染時的外觀(在x坐標上縮放過多)。 我的演員也沒有觸地得分事件。
您需要更新舞台視口。 最好使用resize方法調整視口的大小。
@Override
public void resize(int width, int height) {
stage.getViewport().update(width,height);
//stage.getViewport().update(width,height,true); // -> If you want camera to be at centre.
}
我自己解決了它,我要做的就是在創建后更新視口,例如getViewport().update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.