0
\$\begingroup\$

I'm intending to give an animation to the TextButton by giving the pressedOffsetX and pressedOffsetY values:

TextButtonStyle buttonStyle = new TextButtonStyle();
buttonStyle.font = font25;
buttonStyle.fontColor = Color.WHITE;
buttonStyle.up = new TextureRegionDrawable(settingsAtlas.findRegion("achievements"));
buttonStyle.down = new TextureRegionDrawable(settingsAtlas.findRegion("achievements"));
buttonStyle.pressedOffsetX = 5;
buttonStyle.pressedOffsetY = -5;

And I created a button like this:

TextButton achievementsButton = new TextButton("ACHIEVEMENTS", buttonStyle);
achievementsButton.addListener(new ChangeListener() {
    @Override
    public void changed(ChangeEvent event, Actor actor) {
        // show achievements
    }
});

But when I click the button, only the text in it is animated. The button background stays in the same position. What might I be doing wrong here?

\$\endgroup\$
2
  • 1
    \$\begingroup\$ I believe offset only effects the children of the button. Do it works correctly. \$\endgroup\$
    – Madmenyo
    Aug 2, 2015 at 20:34
  • \$\begingroup\$ @Menno Gouw Oh! That's too bad. It woked for ImageButton, but I now I guess it's because the image was the child of the button? \$\endgroup\$
    – Neerkoli
    Aug 3, 2015 at 3:10

2 Answers 2

1
\$\begingroup\$

As the comment says offset only effects the children, i.e the text inside the button.

What you need to look at is this piece of code:

buttonStyle.up = new TextureRegionDrawable(settingsAtlas.findRegion("achievements"));
buttonStyle.down = new TextureRegionDrawable(settingsAtlas.findRegion("achievements"));

Since you set the same image for up and down you wont see any change on the actual button when you click it. You need to change down to whatever color or image you want to show on click, giving it an animation effect.

If you want the actual button to 2move" like the text inside it, well I don't think libdx has any built in methods for that.

\$\endgroup\$
1
  • \$\begingroup\$ Yeah I guess changing the up and down images is the only option. \$\endgroup\$
    – Neerkoli
    Aug 3, 2015 at 3:11
0
\$\begingroup\$

Sorry yesterday I was a wreck :) but I just found a solution for you. Simply build up the button yourself... lol, I cannot believe I didn't think of that yesterday?

Button button = new Button();
        button.setDebug(true);
        Button.ButtonStyle style = new Button.ButtonStyle();
        style.pressedOffsetX = 100;
        Label label = new Label("Touch me!", skin);
        button.add(label);
        button.setStyle(style);

        button.addListener(new ClickListener()
        {
            @Override
            public void clicked(InputEvent event, float x, float y)
            {
                System.out.println("I moved with label background and text of label");
            }
        });

        table.add(button);

You can add any actor you want to the button since it's actually a table with a click state. Anything within the button should be offset and thus you can put a label with background like I did, a stack with an image and label on top or even multiple tables inside the button.

So in your case you just need to setup a label with your text and use your achievements region as the background or seperate image. Put those in your custom made button and you are set.

\$\endgroup\$
1
  • \$\begingroup\$ I tried this but it's not working. The same problem as TextButton - only the text is moving, not the button background. \$\endgroup\$
    – Neerkoli
    Aug 3, 2015 at 6:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .