LibGDX-可滚动表上的参与者组
在我的游戏中,我想画一个2列的表格,其中包含正方形(如卡片),上面是一个图像和两个标签(作为一行,在卡片顶部是图像,下面是一个标签,下面是另一个标签) 如果我只在我的可滚动表格中放置图像,我会得到想要的结果,但现在我正试图在背景上添加图像和标签 我已经尝试定义一个Actor组并将其添加到表中,但是有些元素没有出现,还扩展了Image类并在onDraw方法中绘制了其他元素,但是当用户滚动时,文本不会随着卡片背景移动 我的表格代码如下:LibGDX-可滚动表上的参与者组,libgdx,scene2d,Libgdx,Scene2d,在我的游戏中,我想画一个2列的表格,其中包含正方形(如卡片),上面是一个图像和两个标签(作为一行,在卡片顶部是图像,下面是一个标签,下面是另一个标签) 如果我只在我的可滚动表格中放置图像,我会得到想要的结果,但现在我正试图在背景上添加图像和标签 我已经尝试定义一个Actor组并将其添加到表中,但是有些元素没有出现,还扩展了Image类并在onDraw方法中绘制了其他元素,但是当用户滚动时,文本不会随着卡片背景移动 我的表格代码如下: Table scrollTable = new 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是我用来显示表项的类。如果我用一个常规的Scene2D图像类替换这个类,所有内容都显示得很好,但是尝试在背景上添加另一个图像和两个标签(通过使HighScoreItem从组扩展或通过使其从图像扩展)是个问题。
有什么办法吗?
谢谢。如果您想使演员彼此重叠,可以使用stack类
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 );
偏移量是从堆栈的左上角开始的。如果要渲染每个角色的顶部,可以使用堆栈类
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 );
偏移量是从堆栈的左上角开始的