重新调整ImageButton的大小 - Scene2d

时间:2014-07-09 11:46:44

标签: libgdx

我正在使用libgdx + scene2d + box2d。在我决定将TextButtons替换为ImageButton之前,一切都很好看。

我无法重新定义我的ImageButton,它始终遵循图像尺寸。

这是我的舞台:

        stage = new Stage(new StretchViewport(camera.viewportWidth,camera.viewportHeight));



这是如何创建我的按钮:

    ImageButtonStyle style = new ImageButtonStyle();
    style.imageUp =  new TextureRegionDrawable(textureButtonPlay);
    ImageButton buttonPlay = new ImageButton(style);
    buttonPlay.setSize(50, 20); //this does not work



这是如何创建我的窗口并添加我的按钮:

    WindowStyle windowStyle = new WindowStyle(new BitmapFont(), Color.WHITE, null);

    windowTryAgain = new Window("", windowStyle);
    windowTryAgain.setMovable(false);
    //windowTryAgain.padTop(20);


    windowTryAgain.setSize(150,150);
    windowTryAgain.setPosition(camera.viewportWidth/2 - windowTryAgain.getWidth()/2,
            camera.viewportHeight/2 - windowTryAgain.getHeight()/2);

    windowTryAgain.row().fill().expandX();
    windowTryAgain.add(buttonPlay).padTop(25).expandX().fillX();
    windowTryAgain.center();



是否可以调整Texture或TextureRegion的大小?什么是最好的方法?

1 个答案:

答案 0 :(得分:1)

我的问题已通过以下代码解决:

windowTryAgain.add(buttonMenu).WIDTH(100).height(100);

然后图像将根据单元格的宽度和高度调整大小。

现金:

scene2d button scaling with libgdx

相关问题