java - libgdx scrollpane不会滚动

时间:2017-06-23 20:56:14

标签: java android libgdx tablelayout

我目前还不知道今天在libGDX(仅限Android)上发生了什么...... 我有我的美丽表,按钮和其他一些东西,我添加了ScrollPane滚动(显然),然后我在其他表中添加了所有内容并将大小值更改为屏幕中心,缩放等等。现在ScrollPane没有工作......

buttonsTable = new Table();
buttonsTable.center().center();
// adding buttons and buttons and more buttons...
ScrollPane scroller = new ScrollPane(buttonsTable);
scroller.layout();
scrollableTable = new Table();
scrollableTable.center().center();
scrollableTable.add(scroller);
this.stage.addActor(scrollableTable);

// SIZE_WIDTH and SIZE_HEIGHT are the size of my screen
scrollableTable.pack();
scrollableTable.setTransform(true);
scrollableTable.setScale(0.5f,0.5f); // I changed the scale of the table(1/2)
scrollableTable.setPosition(SIZE_WIDTH/2 - scrollableTable.getWidth()/4, SIZE_HEIGHT/2 - scrollableTable.getHeight()/4); 
// It doesn't update its height and width, so I just divide by 2 and by 2 again to go to the center

桌子位于我的屏幕中央,但现在ScrollPane被打破了......#/ p>

OBS:我在屏幕的构造函数中调用stage.act(Gdx.graphics.getDeltaTime())内的render()Gdx.input.setInputProcessor(stage);

1 个答案:

答案 0 :(得分:0)

我测试了滚动的ScrollPane

public class TestClass extends ApplicationAdapter {

    Stage stage;
    ExtendViewport extendViewport;

    @Override
    public void create() {

        extendViewport =new ExtendViewport(640,400);

        stage=new Stage(extendViewport);
        Skin skin=new Skin(Gdx.files.internal("skin/glassy-ui.json"));

        Table scrollableTable = new Table();
        scrollableTable.setFillParent(true);
        stage.addActor(scrollableTable);

        Table table = new Table();
        table.add(new TextButton("WELCOME",skin)).row();
        table.add(new TextButton("TO",skin)).row();
        table.add(new TextButton("LIBGDX",skin)).row();
        table.add(new TextButton("GAMING",skin)).row();
        table.add(new TextButton("FRAMEWORK",skin)).row();
        table.pack();
        table.setTransform(true);  //clipping enabled

        table.setOrigin(table.getWidth()/2,table.getHeight()/2);
        table.setScale(.5f);

        final ScrollPane scroll = new ScrollPane(table, skin);
        scrollableTable.add(scroll).expand().fill();

        stage.setDebugAll(true);
        Gdx.input.setInputProcessor(stage);
    }

    @Override
    public void render() {

        Gdx.gl.glClearColor(0, 0, 0, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

        stage.draw();
        stage.act();
    }

    @Override
    public void dispose() {
        stage.dispose();
    }

    @Override
    public void resize(int width, int height) {
        stage.getViewport().update(width,height);
        stage.getCamera().position.set(320,200,0);
        stage.getCamera().update();
   }
}