android - libgdx 中的水平滚动 Pane 级别菜单?

标签 android libgdx scrollpane

在我自上而下的游戏中,我想将滚动 Pane 的位置从垂直更改为水平滚动 Pane 。我想改变滚动的方向。 This image explain my problem屏幕输出 Screen menu

下面是我的代码

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
}

谢谢和进步我是这个框架的新手:)

最佳答案

row() 在下一行终止,你需要在一个水平行中,所以删除 row() :

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

关于android - libgdx 中的水平滚动 Pane 级别菜单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44107178/

相关文章:

java - 如何检测 libGdx 中的文本点击

java - 带有 BufferedImage 的 ScrollPane 不滚动

JavaFX scrollpane - 带滚轮的水平平移

java - ScrollPane javafx自动滚动(将vvalue设置为1.0)仅滚动到最后一项之前的项目

android - 如何在 imageview 中一次显示单个图像?

Android Studio增量混淆导致错误: cannot find symbol class

java - Android:在 View 中使用观察者模式(可能与 MVC、MVVM 相关)

java - 在 libgdx 中使用filledcircle和pixmap

android - 从 aab 文件生成 Apk 文件(Android 应用程序包)

java - LibGDX 上两个不同的文本按钮没有响应