【问题标题】:Libgdx Scene2d Button scaling based on TextureAtlas基于TextureAtlas的Libgdx Scene2d按钮缩放
【发布时间】:2018-03-10 07:34:29
【问题描述】:

我正在尝试创建一个按下时会缩放的按钮。

        textureAtlas = assetManager.get("btn.txt", TextureAtlas.class);
        skin = new Skin(textureAtlas);
        btnStyle = new Button.ButtonStyle();
        btnStyle.up = howToBtn_skin.getDrawable("button");
        btnStyle.down = howToBtn_skin.getDrawable("button_pushed");
        myButton = new Button(btnStyle);
        howToBtn.setPosition((Constant.WIDTH / 2) - 41, (Constant.HEIGHT / 2 - 150));

“按钮” - 是较小的一个

“button_pushed” - 较大的一个

该按钮在单击时会切换图像,但不会根据图像大小进行缩放。所以当用户点击按钮时,看起来什么都没有发生,因为按钮的大小保持不变。

【问题讨论】:

    标签: java libgdx scene2d


    【解决方案1】:

    按钮的大小保持不变(正常状态和按下状态),您需要一些 UI 交互触摸感觉。

    三个选项。 1st 和 2nd 的上下文相似。

    1. 获取两个按钮状态图像(button-up,button-down),尺寸相同但色调值不同。像这样-

    2. 如果您想要相同的色调值,请缩小向下状态按钮图像的图像,但尺寸应该相同。两种状态的画布大小应该相同,并且您必须按中心缩小。

    3. 触摸按钮时自己缩放按钮。您也可以在按钮上添加Action,这样效果会更好。您必须在按钮上启用转换。

      button.setTransform(true);
      button.setScale(0.5f); 
      

    【讨论】:

    • 所以无法使用 textureAtlas 图像缩放按钮?因为我不想让我的按钮在点击时放大,但在释放时恢复到原来的大小
    • 使用第二个或第三个选项,textureAtlas 只包含图像。那里没有规模的概念。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-15
    • 2015-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-08
    相关资源
    最近更新 更多