LibGDX and ScrollPane with multiple widgets(具有多个小部件的 LibGDX 和 ScrollPane)
问题描述
尝试将多个项目添加到滚动窗格中,我很快发现所有addActor"函数都不支持.因此,我添加了一个包含我想要的所有项目的表格(此代码错过了我仍想添加的图像)以制作可滚动的信用屏幕......但这种方法(当前)不允许溢出,渲染ScrollPane 没用.(我的文字只显示到屏幕允许的高度,并且不可滚动).在 LibGDX 中制作具有多个小部件的可滚动窗格的方法是什么?(我目前只关心Android和Win/Lin/Mac平台.
Trying to add multiple items to a scrollpane I quickly found that all "addActor" functions are Unsupported. So, I went with adding a table with all the items I wanted (this code misses a image that I still want to add) to make a scrollable credits screen... but this approach (currently) doesn't allow for overflow, rendering the ScrollPane useless. (My text is only shown up to what the screen's height allows, and isn't scrollable). What's the way to make a scrollable pane with multiple widgets in LibGDX? (I only care about Android and Win/Lin/Mac platforms at the moment.
pane = new ScrollPane(null, skin);
pane.setFillParent(true);
paneContent = new Table(skin);
paneContent.setFillParent(true);
Label temp = new Label("", skin);
temp.setAlignment(Align.left, Align.center);
temp.setText( Gdx.files.internal("licenses/credits.txt").readString("UTF-8") );
paneContent.addActor(temp);
pane.setWidget(paneContent);
stage.addActor(pane);
推荐答案
如果你想将多个项目放入 ScrollPane 中,你只需要在其中放入一个表格,然后为要放入的每个小部件调用 add()滚动窗格.
If you want to put multiple items into the ScrollPane you simply need to put a table into it and call add() for each widget you want to put into the ScrollPane.
以下是如何使您的信用可滚动的示例:
Below is an example of how to make your credits scrollable:
public class ScrollTest implements ApplicationListener {
private Stage stage;
private static final String reallyLongString = "This
Is
A
Really
Long
String
That
Has
Lots
Of
Lines
And
Repeats.
"
+ "This
Is
A
Really
Long
String
That
Has
Lots
Of
Lines
And
Repeats.
"
+ "This
Is
A
Really
Long
String
That
Has
Lots
Of
Lines
And
Repeats.
";
@Override public void create() {
this.stage = new Stage();
Gdx.input.setInputProcessor(this.stage);
final Skin skin = new Skin(Gdx.files.internal("skin/uiskin.json"));
final Label text = new Label(reallyLongString, skin);
text.setAlignment(Align.center);
text.setWrap(true);
final Label text2 = new Label("This is a short string!", skin);
text2.setAlignment(Align.center);
text2.setWrap(true);
final Label text3 = new Label(reallyLongString, skin);
text3.setAlignment(Align.center);
text3.setWrap(true);
final Table scrollTable = new Table();
scrollTable.add(text);
scrollTable.row();
scrollTable.add(text2);
scrollTable.row();
scrollTable.add(text3);
final ScrollPane scroller = new ScrollPane(scrollTable);
final Table table = new Table();
table.setFillParent(true);
table.add(scroller).fill().expand();
this.stage.addActor(table);
}
@Override public void render() {
this.stage.act();
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
this.stage.draw();
}
@Override public void resize(final int width, final int height) {}
@Override public void pause() {}
@Override public void resume() {}
@Override public void dispose() {}
}
添加了在 ScrollPane 中设置表格的代码.
Added code on setting up a table inside of a ScrollPane.
这篇关于具有多个小部件的 LibGDX 和 ScrollPane的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:具有多个小部件的 LibGDX 和 ScrollPane


基础教程推荐
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- 大摇大摆的枚举 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- 从 python 访问 JVM 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- Java Swing计时器未清除 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 多个组件的复杂布局 2022-01-01