Java libGDX-FitViewport不能很好地扩展舞台
我想做的是为我的世界设置一个虚拟大小,并在不改变纵横比的情况下尽可能地在屏幕上缩放这个世界,FitViewport似乎是最好的选择。这就是我在舞台上如何使我的视野变得更加真实Java libGDX-FitViewport不能很好地扩展舞台,java,libgdx,viewport,Java,Libgdx,Viewport,我想做的是为我的世界设置一个虚拟大小,并在不改变纵横比的情况下尽可能地在屏幕上缩放这个世界,FitViewport似乎是最好的选择。这就是我在舞台上如何使我的视野变得更加真实 public class PlayStage extends Stage{ public static final int WIDTH = 480; public static final int HEIGHT = 800; private final Vector2 gravity = n
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坐标上渲染比例过大时精灵的外观。我也没有为我的演员安排触地事件
我自己解决了这个问题,我所要做的就是在创建后更新视口,比如getViewport.updateGdx.graphics.getWidth,Gdx.graphics.getHeight 您需要更新舞台视口。最好使用“调整大小”方法调整视口的大小
@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.
}