LibGDX 在没有舞台的情况下绘制滚动窗格

LibGDX Draw Scrollpane WITHOUT Stage

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

batcher.draw(scrollpane);

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

每个演员都有绘制和表演功能,当您将它们附加到舞台时,舞台会调用这些功能。所以你需要做的就是自己调用 draw。而且由于您想要与滚动窗格进行交互,因此您还需要对其调用 act 。它还需要一个 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);