繁体   English   中英

libgdx ScrollPane - 不滚动?

[英]libgdx ScrollPane - Doesn't scroll?

我正在多人游戏中创建大厅,表格中可能显示任意数量的玩家。 我有以下代码:

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();
    }

尽管表格明显延伸到屏幕底部(应该是滚动窗格的底部)下方,但没有滚动条,单击和拖动也没有任何作用。

截屏:在此处输入图像描述

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

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

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

添加的简单示例:

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

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


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

也许你忘记在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();
}

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

在您初始化滚动窗格后,您应首先调用它

    mScrollPane.layout();

2023 | 年 KOTLIN

要滚动的元素必须先添加到舞台或组,然后再传递给 ScrollPane

  1. 创建必要的演员并将其添加到舞台或组中

    val actor = Actor() [Stage/Group].addActor(actor)
  2. 创建一个 ScrollPane 并在其中放置一个 actor

     val scrollPane = ScrollPane(actor)
  3. 为 actor 和 ScrollPane 设置 position 和尺寸

    actor.setBounds(x,y,w,h) | scrollPane.setBounds(x,y,w,h)

附言。 Vel_daN:热爱你所做的。


暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM