第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

LibGdx Box2d 和 Scene2d 上不同設(shè)備之間的縮放

LibGdx Box2d 和 Scene2d 上不同設(shè)備之間的縮放

慕萊塢森 2023-07-28 10:09:33
我正在使用 Scene2d 和 Box2d 來(lái)處理 LibGdx。我使用 Scene2D 設(shè)計(jì)了 2 個(gè)階段。第一個(gè)階段用于 GUI,例如按鈕,第二個(gè)階段包含帶有固定到我的 Box2d 對(duì)象坐標(biāo)的圖像的 Actor(在我的例子中是簡(jiǎn)單的矩形):當(dāng)我在 PC 上運(yùn)行游戲時(shí),我得到以下圖像:當(dāng)我在 Galaxy S9+ 上運(yùn)行它時(shí),我收到以下圖像:正如您所看到的,背景和 box2d 對(duì)象在 PC 和 Android 上都能正確縮放。問(wèn)題是,與 Android 相比,我的演員圖像在 PC 上發(fā)生了位移(牛仔圖像)。我縮放 Box2D 以獲得更好的物理效果,但從那時(shí)起我在跨平臺(tái)縮放對(duì)象時(shí)遇到了麻煩。代碼:    //My base screen, other screens extend this one:    public BaseScreen(){    Box2D.init();    mainStage = new Stage();    uiStage = new Stage();    manager = new AssetManager();    debug= new Box2DDebugRenderer();    world = new World(new Vector2(0,0),false);    loadAssetmanager();    //Box2d Sprites are initialzed in here:    initialize();    camera= new OrthographicCamera();    camera.setToOrtho(false,1024,1024);    debugMatrix= camera.combined.cpy();    debugMatrix.scale(32,32,0);    mainStage.getViewport().setCamera(camera);    camera.update();    //This BaseScreen class will initialize all assets from its subclasses here.    setMultiplexer();    }背景:我是一名住院醫(yī)師,自學(xué)爪哇語(yǔ)。我正在嘗試為我的醫(yī)學(xué)生設(shè)計(jì)一個(gè)小型模擬,我希望他們能夠在個(gè)人電腦、手機(jī)或平板電腦上訪問(wèn)它。我需要基本的 Box2D 物理(我沒(méi)有時(shí)間在每周工作 40-70 小時(shí)的情況下編寫(xiě)自己的物理引擎),因此 LibGdx 和 Box2d 對(duì)我來(lái)說(shuō)是理想的框架。任何意見(jiàn)將不勝感激。
查看完整描述

1 回答

?
斯蒂芬大帝

TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超8個(gè)贊


這是一個(gè)簡(jiǎn)單的。我初始化了 mainStage() 并且沒(méi)有向它傳遞視口。因此 LibGdx 創(chuàng)建了自己的默認(rèn)視口。當(dāng)我查看 LibGdx 中 Stage() 類(lèi)構(gòu)造函數(shù)的源代碼時(shí),我發(fā)現(xiàn)默認(rèn)的 Viewport 是一個(gè)設(shè)置為 Gdx.graphics.getWidth()、Gdx.graphics.getHeight() 的 ScalingViewport,這會(huì)讀取每個(gè)設(shè)備的寬度/高度并以不同的方式縮放它:


? ? /** 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;

? }

因此,為了解決該問(wèn)題,我更改了以下代碼,而不是:


mainStage = new Stage();

我將代碼更改為,以便每個(gè)設(shè)備都會(huì)縮放到相同的寬度/高度:


?mainStage = new Stage(new StretchViewport(1024,1024));

此更改基本上將視口設(shè)置為 1024x1024 像素,現(xiàn)在可以在我的 PC、Galaxy S9+/其他設(shè)備上正確縮放。


查看完整回答
反對(duì) 回復(fù) 2023-07-28
  • 1 回答
  • 0 關(guān)注
  • 170 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)