libgdx ScrollPane - 不滚动?

csg*_*000 5 java android scrollpane libgdx

我正在一个多人游戏中进行游说,可能会在桌子上显示任意数量的玩家.我有以下代码:

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();
    }
Run Code Online (Sandbox Code Playgroud)

尽管表格明显地延伸到屏幕底部(应该是滚动窗格的底部)之下,但没有滚动条,点击和拖动什么都不做.

截图: 在此输入图像描述

Ben*_*nnX 7

你确实需要两件事.外部容器和内部容器.为此,您经常使用两个表.所以这里有一个小例子我如何使用scrollPane.实际上没有风格,但它应该说清楚.

this.table = new Table();
this.container = new Table();
scroll = new ScrollPane(table);
container.add(scroll).width(500f).height(500f);
container.row();
Run Code Online (Sandbox Code Playgroud)

该表是您添加应该可滚动的内容的表.容器是外盒.因此,您可以在滚动条上方添加标题.外箱(容器)确实需要一个尺寸.否则你不会有任何滚动条等.你确实需要内表.

添加的简单示例:

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

给它更多的线条,它可以显示,你将有一个滚动窗格.否则没有滚动条等.


一体.你错过了我认为的外部容器.添加它,它应该工作.不要忘记设置尺寸.


小智 7

也许你忘记在render()中进行舞台表演,添加如下内容:

@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();
}
Run Code Online (Sandbox Code Playgroud)


csg*_*000 2

我的问题是没有收到输入。我不应该在构造函数中设置输入处理器,因为前一个屏幕在“隐藏”时将处理器设置为 null,所以当我将该行移至 LobbyScreen 的 show 方法时,它发生在前一个屏幕隐藏之后,并且输入设置正确。