1 回答

TA貢獻1827條經驗 獲得超8個贊
這是一個簡單的。我初始化了 mainStage() 并且沒有向它傳遞視口。因此 LibGdx 創建了自己的默認視口。當我查看 LibGdx 中 Stage() 類構造函數的源代碼時,我發現默認的 Viewport 是一個設置為 Gdx.graphics.getWidth()、Gdx.graphics.getHeight() 的 ScalingViewport,這會讀取每個設備的寬度/高度并以不同的方式縮放它:
? ? /** Creates a stage with a {@link ScalingViewport} set to {@link?
? ? ? ? Scaling#stretch}. The stage will use its own {@link Batch}
? ? *? ?which will be disposed when the stage is disposed. */
?public Stage () {
? ? this(new ScalingViewport(Scaling.stretch, Gdx.graphics.getWidth(),?
? ? Gdx.graphics.getHeight(), new OrthographicCamera()), new SpriteBatch());
? ? ownsBatch = true;
? }
因此,為了解決該問題,我更改了以下代碼,而不是:
mainStage = new Stage();
我將代碼更改為,以便每個設備都會縮放到相同的寬度/高度:
?mainStage = new Stage(new StretchViewport(1024,1024));
此更改基本上將視口設置為 1024x1024 像素,現在可以在我的 PC、Galaxy S9+/其他設備上正確縮放。
添加回答
舉報