0
votes

What I want to do is have a virtual size for my world and scale that world on the screen as much as possible without changing the aspect ratio, the FitViewport seemed like the best candidate. Thats how I intialised my viewport on the stage.

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();
}}

This is how the sprite looks when rendered (scaled too much on the x coordinate). Also I get no touch down events for my actors.

enter image description here

2

2 Answers

1
votes

You need to update stage viewport. It's better to resize your viewport from resize method.

@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.
}
0
votes

I solved it on my own, all I had to do was to update the viewport after creation like this getViewport().update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());