简体   繁体   English

在libgdx视口中更改视口

[英]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). 因此,我有2个屏幕:一个级别选择屏幕,该屏幕使用分辨率为720 x 405的FitViewport,然后是一个游戏屏幕,其使用分辨率为480 x 270的FillViewport(按每米像素数(/ 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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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