簡體   English   中英

沒有舞台的LibGDX繪制滾動窗格

[英]LibGDX Draw Scrollpane WITHOUT Stage

我有一個用LibGDX制作的游戲,我的游戲中根本沒有實現scene2d或舞台或演員,但是現在需要滾動窗格。 我所看到的每個示例都使用階段和角色來繪制滾動窗格,是否可以使用批處理程序或其他方法來繪制滾動窗格? 像這樣:

batcher.draw(scrollpane);

而不是創建一個我根本沒有做過的整個舞台。

每個演員都有一個繪畫和表演功能,當您將它們附加到舞台上時,這些會被該舞台調用。 因此,您需要做的就是自己畫畫。 而且,由於您要與滾動窗格進行交互,因此還需要對其進行調用。 它還需要一個GestureListener因此您可以滾動它,否則舞台可能會處理更多的東西。

scrollpane.act(deltaTime);
scrollpane.draw(spriteBatch, alpha);

我真的很想知道為什么您不想要一個舞台。 Stage為您提供了大量的功能和可伸縮性。 是的,對於整個階段而言,僅一個滾動窗格可能就算是過大了,但它不會消耗您的資源。 而且您也需要演員來填充滾動窗格(您也想自己處理所有這些嗎?)。 我真的找不到離開舞台的理由,它只是幾行代碼。

由於您不願在這里學習舞台的工作原理,因此對於Stage的基本用法了解甚少,因此可能會對您有所幫助。

Stage stage = new Stage();

stage.act();
stage.draw();
//This is pretty much it, you can start adding actors to it now.


Table myTable = new Table();
myTable.setFillParent = true; // <-- sets initial table to fill it's parent (in this case the stage)
Scrollpane myScrollpane = new Scrollpane(); // <-- Add actors to hold by scrollpane

myTable.add(myScrollpane);
stage.addActor(myTable);
stage.addActor(myTable);

為了能夠與舞台進行交互,您需要將其設置為輸入處理器。

Gdx.input.setInputProcessor(stage);
//If you want multiple input processors you need to use a InputMultiplexer

InputMultiplexer im = new InputMultiplexer();
im.addProcessor(stage);
im.addProcessor(new GestureDetector(someScreen));
im.addProcessor(player.getInputProcessor);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM