LibGDX - 可滚动的 Actor 组 table
LibGDX - Actor group on scrollable table
在我的游戏中,我想绘制一个 2 列 table,其中包含正方形(如卡片),在它们上面,一个图像和两个标签(作为一行,在卡片的顶部图片,在它下面有一个标签,在它下面有另一个标签)。
如果我只在我的可滚动 table 中放置图像,我会得到想要的结果,但现在我试图在背景上添加图像和标签。
我试过定义一个 Actor 组并将其添加到 table,但有些元素没有出现,还扩展了图像 class 并在 onDraw 方法中绘制了其他元素,但是随着用户滚动,文本不会随卡片背景一起移动。
我的table代码如下:
Table scrollTable = new Table();
scrollTable.align(Align.topLeft);
scrollTable.add(new HighScoreItem(game, Colors.ORANGE, "1º:FER", 30))
.width(190).height(150).space(30);
scrollTable.add(new HighScoreItem(game, Colors.ORANGE, "1º:FER", 30))
.width(190).height(150).space(30);
scrollTable.row();
scrollTable.add(new HighScoreItem(game, Colors.ORANGE, "1º:FER", 30))
.width(190).height(150).space(30);
scrollTable.add(new HighScoreItem(game, Colors.ORANGE, "1º:FER", 30))
.width(190).height(150).space(30);
scrollTable.row();
scrollTable.add(new HighScoreItem(game, Colors.ORANGE, "1º:FER", 30))
.width(190).height(150).space(30);
scrollTable.add(new HighScoreItem(game, Colors.ORANGE, "1º:FER", 30))
.width(190).height(150).space(30);
scrollTable.row();
scrollTable.add(new HighScoreItem(game, Colors.ORANGE, "1º:FER", 30))
.width(190).height(150).space(30);
scrollTable.add(new HighScoreItem(game, Colors.ORANGE, "1º:FER", 30))
.width(190).height(150).space(30);
scrollTable.row();
scrollTable.add(new HighScoreItem(game, Colors.ORANGE, "1º:FER", 30))
.width(190).height(150).space(30);
scrollTable.add(new HighScoreItem(game, Colors.ORANGE, "1º:FER", 30))
.width(190).height(150).space(30);
scrollTable.row();
ScrollPane scroller = new ScrollPane(scrollTable);
Table table = new Table();
table.setBounds(33, 10, 410, 500);
table.add(scroller).fill().expand();
getStage().addActor(table);
HighscoreItem 是我用来显示 table 项目的 class。如果我用常规 Scene2D 图像 class 替换此 class 一切都显示得很好,但尝试在背景上添加另一个图像和两个标签(通过使 HighScoreItem 从 Group 扩展或使其扩展来自图像)是问题所在。
关于如何做到这一点的任何想法?
谢谢。
如果你想在彼此之上渲染演员,你可以使用堆栈 class。
Stack stack = new Stack();
stack.add( new Image( new Texture( "test.png" ) ) );
stack.add( new Label( "label 1", skin ) );
stack.add( new Label( "label 2", skin ) );
scrollTable.add( stack );
偏移量是从堆栈的左上角开始。
在我的游戏中,我想绘制一个 2 列 table,其中包含正方形(如卡片),在它们上面,一个图像和两个标签(作为一行,在卡片的顶部图片,在它下面有一个标签,在它下面有另一个标签)。
如果我只在我的可滚动 table 中放置图像,我会得到想要的结果,但现在我试图在背景上添加图像和标签。
我试过定义一个 Actor 组并将其添加到 table,但有些元素没有出现,还扩展了图像 class 并在 onDraw 方法中绘制了其他元素,但是随着用户滚动,文本不会随卡片背景一起移动。
我的table代码如下:
Table scrollTable = new Table();
scrollTable.align(Align.topLeft);
scrollTable.add(new HighScoreItem(game, Colors.ORANGE, "1º:FER", 30))
.width(190).height(150).space(30);
scrollTable.add(new HighScoreItem(game, Colors.ORANGE, "1º:FER", 30))
.width(190).height(150).space(30);
scrollTable.row();
scrollTable.add(new HighScoreItem(game, Colors.ORANGE, "1º:FER", 30))
.width(190).height(150).space(30);
scrollTable.add(new HighScoreItem(game, Colors.ORANGE, "1º:FER", 30))
.width(190).height(150).space(30);
scrollTable.row();
scrollTable.add(new HighScoreItem(game, Colors.ORANGE, "1º:FER", 30))
.width(190).height(150).space(30);
scrollTable.add(new HighScoreItem(game, Colors.ORANGE, "1º:FER", 30))
.width(190).height(150).space(30);
scrollTable.row();
scrollTable.add(new HighScoreItem(game, Colors.ORANGE, "1º:FER", 30))
.width(190).height(150).space(30);
scrollTable.add(new HighScoreItem(game, Colors.ORANGE, "1º:FER", 30))
.width(190).height(150).space(30);
scrollTable.row();
scrollTable.add(new HighScoreItem(game, Colors.ORANGE, "1º:FER", 30))
.width(190).height(150).space(30);
scrollTable.add(new HighScoreItem(game, Colors.ORANGE, "1º:FER", 30))
.width(190).height(150).space(30);
scrollTable.row();
ScrollPane scroller = new ScrollPane(scrollTable);
Table table = new Table();
table.setBounds(33, 10, 410, 500);
table.add(scroller).fill().expand();
getStage().addActor(table);
HighscoreItem 是我用来显示 table 项目的 class。如果我用常规 Scene2D 图像 class 替换此 class 一切都显示得很好,但尝试在背景上添加另一个图像和两个标签(通过使 HighScoreItem 从 Group 扩展或使其扩展来自图像)是问题所在。 关于如何做到这一点的任何想法? 谢谢。
如果你想在彼此之上渲染演员,你可以使用堆栈 class。
Stack stack = new Stack();
stack.add( new Image( new Texture( "test.png" ) ) );
stack.add( new Label( "label 1", skin ) );
stack.add( new Label( "label 2", skin ) );
scrollTable.add( stack );
偏移量是从堆栈的左上角开始。