2017-08-20 47 views
1

在我的遊戲中,我想繪製一個包含正方形(如卡片)的2列表格,並在它們上方繪製一個圖像和兩個標籤(作爲行,位於卡片頂部圖像下面是一個標籤,下面是另一個標籤)。LibGDX - 可滾動表上的演員組

如果我只在可滾動表格中放置圖像,我會得到所需的結果,但現在我試圖將圖像和標籤添加到背景上。

我試過定義一個Actor組並將其添加到表中,但是一些元素不會出現,也會擴展Image類並在onDraw方法中繪製其他元素,但隨後文本不會隨着作爲用戶滾動的卡片背景。

我的表的代碼如下:

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 Image類替換這個類,一切都顯示得很好,但試圖在背景中添加另一個圖像和兩個標籤(通過使HighScoreItem從Group擴展或通過擴展Image來實現)是問題所在。 關於如何做到這一點的任何想法? 謝謝。

回答

0

如果你想渲染演員在彼此之上,你可以使用棧類。

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); 

偏移量位於堆棧的左上角。