2013-08-01 58 views
5

我在一个多人游戏中制作了一个大厅,其中可能有任意数量的玩家在桌子上显示。我有以下代码:libgdx ScrollPane - 不滚动?

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

尽管在该表明确地扩展画面(它应该是滚动窗格的底部)的底部下方的方式,不存在滚动条,并点击和拖动什么也没做。

截图: enter image description here

回答

2

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

6

你实际上需要两件事情。外部容器和内部容器。你确实为此使用了两个表格。所以这里是一个小例子,我使用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 

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


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

+0

我加外cointainer,和,它仍然不起作用。 – csga5000

+0

另外,你从哪里得到Config.VIRTUAL_VIEW_WIDTH? – csga5000

+0

...这是我在程序中使用的静态浮点数。用一些值替换它 – BennX

1

你初始化滚动面板之后,你应该把这个第一

mScrollPane.layout(); 
7

也许你忘了做舞台表演的渲染(),添加类似:

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