LibGDX Draw Scrollpane没有阶段

时间:2016-03-17 04:28:35

标签: java android scroll libgdx scrollpane

我有一个用LibGDX制作的游戏,我在游戏中根本没有实现过scene2d或阶段或演员,但我现在需要一个滚动窗格。我见过的每个例子都使用舞台和演员来绘制滚动窗格,是否可以使用批处理器或任何东西绘制它?像这样:

batcher.draw(scrollpane);

而不是创造一个我根本没有完成的整个舞台。

1 个答案:

答案 0 :(得分:1)

每个演员都有一个绘画和动作功能,当你把它们附加到一个舞台上时,这个舞台就会被调用。所以你需要做的就是自己打电话。由于您想要与滚动窗格进行交互,因此您还需要对其进行调用。它还需要一个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);
相关问题