2017-05-22 15 views
0

私のトップダウンゲームでは、スクロールペインの位置を垂直方向から水平方向のsrcollpaneに変更したいと考えています。私はスクロールの方向を変えたい。 This image explain my problem画面出力ここ Screen menulibgdxの水平スクロール区画レベルメニュー?

は、私はこのフレームワークに新たなんだ

private Stage stage; 
SpriteBatch spriteBatch; 
OrthographicCamera camera; 
private TextureRegion myTextureRegion; 
private TextureRegionDrawable myTexRegionDrawable; 
Viewport viewport; 
private Texture Background,backToMain,prev,next; 
Texture SelectHouseHold,HouseHold1; 
ImageButton backToMainBtn,prevBtn,nextBtn,selectHouseholdImg; 
ScrollPane scrollPane; 
//container is new 
Table table, container; 
Texture texture1, texture2, texture3, texture4, texture5, texture6; 
ImageButton button1, button2, button3, button4, button5, button6; 

    container = new Table(); 
    table = new Table(); 
    stage.addActor(container); 
    container.setFillParent(true); 

    final ScrollPane scrollPane = new ScrollPane(table); 
    float myPadTop = Gdx.graphics.getWidth()/ 2.4f-scrollPane.getWidth()/2.4f; 
    float myPadBottom = Gdx.graphics.getWidth()/1.2f-scrollPane.getWidth()/1.2f; 

    scrollPane.setFlickScroll(true); 
    container.add(scrollPane).padTop(myPadTop).padBottom(myPadBottom); 
    table.pad(10).defaults().expandY().space(100); 
    scrollPane.setSize(687, 497); 

    texture1 = new Texture(Gdx.files.internal("HouseHold/household1.png")); 
    texture2 = new Texture(Gdx.files.internal("HouseHold/household1.png")); 
    texture3 = new Texture(Gdx.files.internal("HouseHold/household1.png")); 
    texture4 = new Texture(Gdx.files.internal("HouseHold/household1.png")); 
    texture5 = new Texture(Gdx.files.internal("HouseHold/household1.png")); 
    texture6 = new Texture(Gdx.files.internal("HouseHold/household1.png")); 

    button1 = new ImageButton(new Image(texture1).getDrawable()); 
    button2 = new ImageButton(new Image(texture2).getDrawable()); 
    button3 = new ImageButton(new Image(texture3).getDrawable()); 
    button4 = new ImageButton(new Image(texture4).getDrawable()); 
    button5 = new ImageButton(new Image(texture5).getDrawable()); 
    button6 = new ImageButton(new Image(texture6).getDrawable()); 

    //table.setFillParent(true);//Remove 
    //table.defaults().width(Gdx.graphics.getWidth()/2.5f).height(Gdx.graphics.getHeight()/(8* Gdx.graphics.getHeight()/Gdx.graphics.getWidth()));//Remove 

    table.add(button1).row(); 
    table.add(button2).row(); 
    table.add(button3).row(); 
    table.add(button4).row(); 
    table.add(button5).row(); 
    table.add(button6).row(); 

    //scrollPane.setX(Gdx.graphics.getWidth()/2-scrollPane.getWidth()/2);//Remove 
    //scrollPane.setY(Gdx.graphics.getHeight()/2-scrollPane.getHeight()/2);//Remove 

    button1.addListener(new ClickListener(){ 
     @Override 
     public void clicked(InputEvent event, float x, float y) 
     { 
      System.out.println("Next Screen"); 
      stage.getRoot().getColor().a = 1; 
      SequenceAction sequenceAction = new SequenceAction(); 
      sequenceAction.addAction(fadeOut(0.2f)); 
      sequenceAction.addAction(run(new Runnable() { 
       @Override 
       public void run() { 
        // game.setScreen(new SelectDiffculty(game)); 
       } 
      })); 
      stage.getRoot().addAction(sequenceAction); 
     } 
    }); 
    //Back and Next button 
    prev = new Texture(Gdx.files.internal("HouseHold/back.png")); 
    myTextureRegion = new TextureRegion(prev); 
    myTexRegionDrawable = new TextureRegionDrawable(myTextureRegion); 
    prevBtn = new ImageButton(myTexRegionDrawable); //Set the button up 
    prevBtn.setPosition(80,170); 

    stage.addActor(prevBtn); //Add the button to the stage to perform rendering and take input. 
    Gdx.input.setInputProcessor(stage); 
    prevBtn.addListener(new InputListener(){ 
     @Override 
     public void touchUp (InputEvent event, float x, float y, int pointer, int button) { 
      System.out.println("Prev Screen"); 

     } 
     @Override 
     public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) { 
      return true; 
     } 
    }); 
    stage.addActor(prevBtn); 
    //next 
    next = new Texture(Gdx.files.internal("HouseHold/next.png")); 
    myTextureRegion = new TextureRegion(next); 
    myTexRegionDrawable = new TextureRegionDrawable(myTextureRegion); 
    nextBtn = new ImageButton(myTexRegionDrawable); //Set the button up 
    nextBtn.setPosition(500,170); 
    stage.addActor(nextBtn); //Add the button to the stage to perform rendering and take input. 
    Gdx.input.setInputProcessor(stage); 
    nextBtn.addListener(new InputListener(){ 
     @Override 
     public void touchUp (InputEvent event, float x, float y, int pointer, int button) { 
      System.out.println("Next House Hold"); 

     } 
     @Override 
     public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) { 
      return true; 
     } 
    }); 
    stage.addActor(nextBtn); 

} 
@Override 
public void show() { 
    Gdx.input.setInputProcessor(stage); 
    stage.getRoot().getColor().a = 0; 
    stage.getRoot().addAction(fadeIn(0.2f)); 
    //Start taking input from the ui 
} 
@Override 
public void render(float delta) { 
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); // Clear screen 
    camera.update(); 
    spriteBatch.begin(); 
    spriteBatch.setProjectionMatrix(camera.combined); 
    spriteBatch.draw(Background,0,0); 

    stage.act(Gdx.graphics.getDeltaTime()); //Perform ui logic 
    spriteBatch.end(); 
    stage.getViewport().apply(); 
    stage.draw(); //Draw the ui 
} 

感謝の事前:)

+0

ありがとうございました – jaZzZ

答えて

1

row()以下の私のコードは、あなたがそう横一列に必要な、次の行で終了です削除するrow()

table.add(button1); 
table.add(button2); 
table.add(button3); 
table.add(button4); 
table.add(button5); 
table.add(button6);