2017-07-03 52 views
1

所以我有2個屏幕:一個級別選擇屏幕,它使用分辨率爲720 x 405的FitViewport,然後是一個使用FillViewport的分辨率爲480 x 270的遊戲屏幕,每米像素數(/ 100)。在libgdx視口中更改視口

完成某個級別後,我想返回到級別選擇屏幕。然而,在迴歸它似乎在被完全放大

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

Here is how it looks after coming out of the game

這裏是級別的屏幕代碼:

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())); 
+0

這兩個屏幕之間有什麼共同點? – Aryan

+0

你的意思是什麼? –

+0

你有沒有分享像舞臺,相機,視口或其他東西? – Aryan

回答

0

更改視口時需要在繪製之前應用視口:

this.viewport.apply(); 
+0

我試過這個。它不會改變任何東西。 viewport.getWidth和getHeight是正確的,類型也是正確的。 –