I am trying to develop an Android app and I have stumbled across a really nasty problem.
I am trying to use a different viewport from my "main" one for a different stage to control certain elements. I have started using Scaling viewport with Scaling.none, as it seems the most appropriate for what I am looking for. The problem is, when I try to change its position, it simply does not move! It just stays in the center of the screen. Here is the code I am using in the contructor for the viewports:
viewport = new StretchViewport(720, 1280, cam);
viewport.apply();
cam.position.set(cam.viewportWidth / 2, cam.viewportHeight / 2,0);
secondaryViewport = new ScalingViewport(Scaling.none, 480, 421);
secondaryViewport.setScreenPosition(240, 0);
Can't Scaling viewports be moved?
EDIT: Here is my render() method:
@Override
public void render(SpriteBatch sb) {
cam.update();
secondaryViewport.getCamera().update();
sb.setProjectionMatrix(cam.combined);
Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
sb.begin();
sb.setColor(Color.WHITE);
sb.draw(bg, cam.position.x - cam.viewportWidth / 2, 0, cam.viewportWidth, cam.viewportHeight);
sb.end();
stage.getViewport().apply();
stage.draw();
stage.act();
secondaryStage.getViewport().apply();
secondaryStage.draw();
secondaryStage.act();
}
Ok, the solution was
secondaryStage.getViewport().setScreenPosition(x, y);