亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

你如何使用 LibGDX 實現水平滾動?

你如何使用 LibGDX 實現水平滾動?

catspeake 2022-07-27 21:38:16
我想編寫一個類似于舊版“Warfare 1917”瀏覽器游戲的游戲。我被困在滾動部分。我將嘗試用 gif 解釋我想要做什么:https://i.stack.imgur.com/rvZqA.gif 我一整天都在搜索并嘗試了所有東西,但我找不到任何真正的解決方案。我希望你能理解我想要做什么。
查看完整描述

2 回答

?
開心每一天1111

TA貢獻1836條經驗 獲得超13個贊

由于移動相機是一種不好的做法,最好移動一個圖層(你的精靈的容器),或者你可以嘗試ScrollPane,WidgetGroup的實現

請參閱https://libgdx.badlogicgames.com/ci/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/ui/ScrollPane.html

ps 在 v. 1.9.11 上測試


查看完整回答
反對 回復 2022-07-27
?
手掌心

TA貢獻1942條經驗 獲得超3個贊

我認為這應該可以解決問題


public class MovingCamera extends InputAdapter {


    OrthographicCamera camera;    // The camera to be moved

    float pivotX;                 // The pivot for the movement


    public MovingCamera() {

        camera = new OrthographicCamera(); // Initialize camera

    }


    // Create a pivot

    @Override

    public boolean touchDown(int screenX, int screenY, int pointer, int button) {

        Vector3 unprojected = camera.unproject(new Vector3(screenX, screenY, 0)); // Convert from pixel to world coordinates

        pivotX = unprojected.x;                                                   // Save first finger touch on screen (Will serve as a pivot)

        return true;                                                              // Input has been processed

    }


    // Move the camera

    @Override

    public boolean touchDragged(int screenX, int screenY, int pointer) {

        Vector3 unprojected = camera.unproject(new Vector3(screenX, screenY, 0)); // Convert from pixel to world coordinates

        camera.position.x += unprojected.x - pivotX;                              // Change camera position

        camera.update();                                                          // Apply changes

        return true;                                                              // Input has been processed

    }

}

在您的渲染方法中:


public void render(SpriteBatch spriteBatch) {

    spriteBatch.setProjectionMatrix(camera.combined); // Let the Sprite Batch use the camera

    spriteBatch.begin();

    // [Draw your Textures, TextureRegions, Sprites, etc...]

    spriteBatch.end();

}


查看完整回答
反對 回復 2022-07-27
  • 2 回答
  • 0 關注
  • 163 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號