Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

libgdx ScrollPane - Doesn't scroll?

I'm making a lobby in a multi-player game, which may have any number of players displayed in a table. I have the following code:

camera = new OrthographicCamera(WIDTH,HEIGHT);
    camera.position.set(WIDTH/2,HEIGHT/2, 0);
    camera.update();

    stage = new Stage();
    Gdx.input.setInputProcessor(stage);
    stage.setCamera(camera);
    stage.setViewport(WIDTH,HEIGHT,false);

    ScrollPaneStyle paneStyle = new ScrollPaneStyle();
    paneStyle.background = new TextureRegionDrawable(WizardsDuel.atlas.findRegion("cavebg"));
    paneStyle.vScrollKnob = new TextureRegionDrawable(WizardsDuel.atlas.findRegion("GUI/slidernob"));
    paneStyle.hScroll = paneStyle.hScrollKnob = paneStyle.vScroll = paneStyle.vScrollKnob;

    Table container = new Table();
    table = new Table();
    ScrollPane pane = new ScrollPane(table,paneStyle);
    container.add(pane).width(WIDTH).height(HEIGHT);
    container.row();
    container.setBounds(0,0,WIDTH,HEIGHT);
    stage.addActor(container);

    font = new BitmapFont();
    color = new Color(0,0,0,1);
    style = new TextButtonStyle();
    style.font = font;
    style.up = new TextureRegionDrawable(WizardsDuel.atlas.findRegion("GUI/guibg"));
    style.fontColor = color;

    handler = new ChangeHandler();
    ArrayList<User> users = FirebaseManager.lobbyUsers;
    for(int i = 0; i < users.size() || i < 100; i++){
        TextButton tmp = new TextButton("",style);
        tmp.scale(2);
        //tmp.setText(users.get(i).name);
        tmp.setText(i+ "   asdf");
        tmp.addListener(handler);
        table.add(tmp).width(WIDTH/4f);
        if(i%2 == 1 && i > 0)
            table.row();
    }

Despite the manner in which the table clearly extends below the bottom of the screen(which should be the bottom of the scroll pane), there is no scroll bar, and clicking and dragging does nothing.

Screenshot: enter image description here

like image 654
csga5000 Avatar asked Aug 01 '13 14:08

csga5000


2 Answers

maybe you forget to make stage act in render(), add something like:

@Override
public void render(float delta) {
    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    stage.act(Math.min(Gdx.graphics.getDeltaTime(), 1 / 30f));
    stage.draw();
}
like image 94
Jason Wang Avatar answered Sep 20 '22 01:09

Jason Wang


You do actually need two things. An outer Container and an inner Container. You do regularly use two Tables for this. So here is a small example how I use the scrollPane. Actually with no style but it should make it clear.

this.table = new Table();
this.container = new Table();
scroll = new ScrollPane(table);
container.add(scroll).width(500f).height(500f);
container.row();

The table is the table one where you do add the stuff that should be scrollable. The container is the outer box. So you can add for example a headline above your scrollbox. The outer box (container) does need a size. Else you will not have any scrollbars or such. And you do need the inner table.

Simple example for adding:

style = new LabelStyle(font, Color.WHITE);
label = new Label(null, style);
table.add(label);
table.row();
label.setAlignment(1); // align center

give it more lines that it can show and you'll have a scroll pane. Else there is no scrollbar or such.


All in one. You just missed the outer container i think. Add it and it should work. Don't forget to sett the sizes.

like image 20
BennX Avatar answered Sep 23 '22 01:09

BennX