简体   繁体   English

没有舞台的LibGDX绘制滚动窗格

[英]LibGDX Draw Scrollpane WITHOUT Stage

I have a game made with LibGDX, I haven't implemented scene2d or stages or actors at all in my game, but am now in need of a scroll pane. 我有一个用LibGDX制作的游戏,我的游戏中根本没有实现scene2d或舞台或演员,但是现在需要滚动窗格。 Every example I've seen uses stages and actors to draw the scroll pane, is it possible to draw it using a batcher or anything? 我所看到的每个示例都使用阶段和角色来绘制滚动窗格,是否可以使用批处理程序或其他方法来绘制滚动窗格? like so: 像这样:

batcher.draw(scrollpane);

instead of creating a whole stage which I haven't done at all. 而不是创建一个我根本没有做过的整个舞台。

Every actor has a draw and act function and when you attach them to a stage these get called by that stage. 每个演员都有一个绘画和表演功能,当您将它们附加到舞台上时,这些会被该舞台调用。 So all you need to do is call draw yourself. 因此,您需要做的就是自己画画。 And since you want to interact with a scrollpane you also need to call act on it. 而且,由于您要与滚动窗格进行交互,因此还需要对其进行调用。 It also needs a GestureListener so you can scroll it and possibly more stuff the stage would handle otherwise. 它还需要一个GestureListener因此您可以滚动它,否则舞台可能会处理更多的东西。

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

I really do wonder why you do not want a stage. 我真的很想知道为什么您不想要一个舞台。 Stage gives you a ton of functionality and scalability. Stage为您提供了大量的功能和可伸缩性。 Yes for just one scrollpane a whole stage might be overkill but it does not eat your resources. 是的,对于整个阶段而言,仅一个滚动窗格可能就算是过大了,但它不会消耗您的资源。 And you need actors to fill up the scrollpane too (you want to handle these all yourself too?). 而且您也需要演员来填充滚动窗格(您也想自己处理所有这些吗?)。 I cannot really find a reason to leave a stage out, it's just a couple lines of code. 我真的找不到离开舞台的理由,它只是几行代码。

Since you are hesitant of learning how the stage works here is something that might help you out since there is little to understand about the basic usage of 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);

To be able to interact with the stage you need to set it as a input processor. 为了能够与舞台进行交互,您需要将其设置为输入处理器。

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