-1

I am trying to build user interface for leaderboard in my libGDX project using Scene2D. My benchmark is something like Google Play Games/ Game center leaderboard. Kind of like an overlay on an existing screen with refresh ability using slide down.

I am having no ideas as in how to update the data in an already rendered Scene2D element. This is how I am creating the leaderboard. The below function gets called on a button press. Now how to update data in the rendered leaderboard table below on refresh? Same challenge would be for when I would try to change leaderboard type from global to social or alltime to last week.

public Table getLeaderboard(com.myapp.models.Leaderboard[] leaderboards){
    Constants.printLog(TAG,"getLeaderboard function");
    //To check layout. Comment later
    Pixmap pm1 = new Pixmap(1, 1, Pixmap.Format.RGB565);
    pm1.setColor(Color.LIGHT_GRAY);
    pm1.fill();
    // Defining Tables
    final Table rootTable = new Table(); // Root table
    rootTable.setFillParent(true);
    Table navigationTable = new Table(); //Table to done/back button
    Table scoresTable = new Table(); //Table to to show scores



    //    Strings to be used
    String doneString = "done";
    TextButton doneButton = new TextButton(getString(doneString),skin,"default");

    navigationTable.add(doneButton);



    for(int i=0; i<leaderboards.length; i++){
      scoresTable.add(renderScoreRow(leaderboards[i].getName(),leaderboards[i].getHighscore())).expandX().fillX();
      scoresTable.row();
    }

    ScrollPane scoreScrollPane = new ScrollPane(scoresTable);




    rootTable.add(navigationTable).expandX().right().row();
    rootTable.add(scoreScrollPane).expandY().expandX().fillX();

    doneButton.addListener(new InputListener() {
      @Override
      public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
        rootTable.setVisible(false);
        rootTable.remove();
        return true;
      }
    });

    //    navigationTable.setDebug(true);
//    scoresTable.setDebug(true);
    rootTable.setBackground(new TextureRegionDrawable(new TextureRegion(new Texture(pm1))));

    return  rootTable;
  }
Rohit Goyal
  • 1,521
  • 3
  • 24
  • 49

1 Answers1

0

You need to re-create the table. There is no good way to insert/edit in scene2d table