简体   繁体   中英

Viewport changing in libgdx viewport

So I have 2 screens: a level select screen which uses a FitViewport with a resolution of 720 x 405 and then a game screen which uses a FillViewport with a resolution of 480 x 270 scaled by the amount of pixels per meter (/100).

After completing a certain level I want to return to the level select screen. However, upon return it seems to be fully zoomed in.

Here is how it should look, and how it looks when first launched

Here is how it looks after coming out of the game

Here is the level screen code:

public LevelScreen(CrossplatformApp game) {
    this.game = game;
    this.camera = new OrthographicCamera();
    this.levelstage = new Stage(new FitViewport(Constants.WIDTH, Constants.HEIGHT, camera));
    this.background = new Texture("Screens/LevelScreen/LevelSelection.png");
    this.backbutton = new Texture("Screens/BackButton.png");
    this.level1texture = new Texture("Screens/LevelScreen/Button1.png");
    this.level2texture = new Texture("Screens/LevelScreen/Button2.png");
    this.level3texture = new Texture("Screens/LevelScreen/Button3.png");
}

@Override
public void resize(int width, int height) {
    levelstage.getViewport().update(width, height, true);
}

And the game screen:

this.game = gameFile;
    this.camera = new OrthographicCamera();
    this.viewport = new FillViewport(Constants.V_WIDTH / Constants.PPM, Constants.V_HEIGHT / Constants.PPM, camera);
    this.levelHUD = new HUD(gameFile.batch, WorldPicker.getWorldName(playerMemory.player.worldAndLevelData.getCurrentWorld(), playerMemory.player.worldAndLevelData.getCurrentLevel()));

更改视口时,需要在使用以下方法进行绘制之前应用视口:

this.viewport.apply();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM