我有一个用 LibGDX 制作的游戏,我在游戏中根本没有实现 scene2d 或舞台或 Actor ,但现在需要一个滚动 Pane 。我见过的每个例子都使用阶段和 Actor 来绘制滚动 Pane ,是否可以使用批处理器或其他东西来绘制它?像这样:
batcher.draw(scrollpane);
而不是创建一个我根本没有做过的整个舞台。
最佳答案
每个 Actor 都有一个绘制和表演功能,当您将它们附加到舞台时,这些功能会被该舞台调用。所以你需要做的就是自己调用draw函数。由于您想与滚动 Pane 交互,您还需要对其调用 act。它还需要一个 GestureListener
,以便您可以滚动它以及舞台可能要处理的更多内容。
scrollpane.act(deltaTime);
scrollpane.draw(spriteBatch, alpha);
我真的很想知道为什么你不想要一个舞台。 Stage 为您提供了大量的功能和可扩展性。是的,对于一个滚动 Pane 来说,整个阶段可能有点过大,但它不会占用您的资源。而且您还需要 Actor 来填充滚动 Pane (您也想自己处理这些吗?)。我实在找不到省略一个阶段的理由,这只是几行代码。
由于您对学习舞台如何工作犹豫不决,这里可能会对您有所帮助,因为您对 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);
关于java - LibGDX 绘制不带舞台的滚动面板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36051691/