[英]Viewport changing in libgdx viewport
因此,我有2個屏幕:一個級別選擇屏幕,該屏幕使用分辨率為720 x 405的FitViewport,然后是一個游戲屏幕,其使用分辨率為480 x 270的FillViewport(按每米像素數(/ 100)縮放)。
完成某個級別后,我想返回到級別選擇屏幕。 但是,返回時似乎已完全放大。
這是關卡屏幕代碼:
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);
}
和游戲畫面:
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.