【问题标题】:Libgdx - Change button's text label position if button is held downLibgdx - 如果按住按钮,则更改按钮的文本标签位置
【发布时间】:2016-10-18 04:23:01
【问题描述】:

我想要一个具有 3D 效果的按钮,所以如果你按下它,它看起来就像是按下了按钮(在“地面”内)。

像这样:

但我想保存文件大小,只保存没有文字的背景纹理。所以我正在使用 TextButtons 并尝试检测按钮是否像这样“按住”:

    tbs1 = new TextButton.TextButtonStyle();
    tbs1.up = new TextureRegionDrawable(Game.res.getAtlas("buttons_3").findRegion("button3_green_normal"));
    tbs1.down = new TextureRegionDrawable(Game.res.getAtlas("buttons_3").findRegion("button3_green_pressed"));
    tbs1.font = FontManager.bignoodle_90;
    quickMatchButton = new TextButton("Quick Match", tbs1);
    quickMatchButton.getLabelCell().padBottom(ASR.h(50));
    quickMatchButton.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            Game.gsm.setState(Game.gsm.CONFIGUREMATCH);
        }
    });
    quickMatchButton.addListener(new ClickListener() {
        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button){
            //This is not working!
            quickMatchButton.getLabelCell().padBottom(ASR.h(100));
            return true;
        }
    });

问题是(我认为)在将按钮添加到布局表后,我无法更改按钮内文本标签的位置。

所以主要问题:创建按钮后,如何更改按钮内 TextLabel 的位置(或填充)?

感谢您的宝贵时间!

【问题讨论】:

    标签: android user-interface button libgdx


    【解决方案1】:

    你可以试试这个:

    tbs1.pressedOffsetY = -3;
    

    这适用于 ImapgeButton,因为pressedOffsetY 属于 ButtonStyle,它也应该适用于文本按钮。

    【讨论】:

    • 我刚试了,效果很好,你能看看你做了什么吗?
    猜你喜欢
    • 1970-01-01
    • 2017-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多