How to update table row in Libgdx?

1k Views Asked by At

I have a score table with an array of players added in my initial constructor like so:

for( int i=0; i<this.players.size; i++ ) {
    scoreTable.add( new Label(players.get(i).getName(), skin) ); // first column
    scoreTable.add( new Label(players.get(i).getScore() + "", skin) ); // second column
    scoreTable.row();
}

+----------+--------+
| Player A |    0   |
+----------+--------+
| Player B |    0   |
+----------+--------+
| Player C |    0   |
+----------+--------+

Now in my render() method, I want to update the player score in the table but I have no idea how to get the referencing index to be able to do so. Any ideas would be appreciated as I can't seems to find any example on the net or doc.

1

There are 1 best solutions below

3
On BEST ANSWER

The quick way would be to call scoreTable.getChildren() which will return you an SnapshotArray object that holds all child actors of the table.

So if you want to get the first item you could get it like this: scoreTable.getChildren().get(0); etc.