【问题标题】:Re-sizing ImageButton - Scene2d调整 ImageButton 的大小 - Scene2d
【发布时间】:2014-07-09 11:46:44
【问题描述】:

我正在使用 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 的大小?最好的方法是什么?

【问题讨论】:

    标签: libgdx


    【解决方案1】:

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

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

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

    学分:

    scene2d button scaling with libgdx

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-03
      • 1970-01-01
      相关资源
      最近更新 更多