2013-08-01 60 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(); 
}