Change font color of TextButton on click? - libgdx

I've read some tutorials and documentation on scene2d's UI capabilities, but I can't quite figure out how the skins work. I simply want a TextButton that changes color when pressed. I managed to get the background of the TextButton to change, but that's not what I wanted. It should have no background.
I would be very grateful if anyone could provide an example of how this could be done. It seems very simple, so I think I'm missing something obvious here. If a skin is involved, please write it programmatically.
Thank you.

Turns out it was as simple as I thought, it just didn't work when I tried it the first time.
When defining the TextButtonStyle you can assign downFontColor the color you want your text to be while it is being pressed. You can also assign checkedFontColor the color you want the text toggle between when pressed.
Example:
TextButtonStyle textButtonStyle = new TextButtonStyle();
textButtonStyle.font = someBitmapFont;
textButtonStyle.fontColor = Color.WHITE;
textButtonStyle.downFontColor = Color.BLACK;
//Optional color to toggle between when pressed
textButtonStyle.checkedFontColor = Color.GREEN;
final TextButton textButton = new TextButton("Text", textButtonStyle);
This will produce a white TextButton that turns black when it is pressed. When the mouse/touch is released it'll either turn green or white, depending on the state of the toggle.

You can also tint it, but the effect depends on the base color (if it is white, then it works perfectly, else it depends). Anyway, it's done like this:
button.getLabel().setColor(myColor);

Related

Textbutton not working and scaling issues

I've created a table with scened2d that contains buttons, but i have many issues with thoses buttons.
First issue is scaling, whenever i try to set a button's with and height an issue appear
when i set it with :
table.add(btn).with(100).height(30);
or
btnStyle.up.setMinWidth(80);
btnStyle.up.setMinHeight(40);
btnStyle.down.setMinWidth(80);
btnStyle.down.setMinHeight(40);
the button is correctly scaled but the background is acting weird
But if i don't set their with and height, their background are normal but the buttons are way too big
Second issue, the buttons don't "work" as i can't click on then (nothing change)
here is the code
// style
final Skin skin = new Skin(Gdx.files.internal("skin/glassy-ui.json"));
final BitmapFont font = skin.getFont("font");
final TextButton.TextButtonStyle btnStyle = new TextButton.TextButtonStyle();
btnStyle.font = font;
btnStyle.up = skin.getDrawable("button");
btnStyle.down = skin.getDrawable("button-down");
btnStyle.up.setMinWidth(80);
btnStyle.up.setMinHeight(40);
btnStyle.down.setMinWidth(80);
btnStyle.down.setMinHeight(40);
// buttons
Textbutton btn = new TextButton("some text", btnStyle);
how can i scale my buttons correctly and what could cause the buttons to stop working ?
(there is already a question about buttons scaling but it didn't helped much)
For getting the clicks on the button, you have to add a ChangeListener.
The assets you are using as button background are too big, or their padding is too big. Use the Skin Composer to get a preview for your skin.
With the buttons not working, did you remember to call setInputProcessor on your stage?

Change color of clicked button AS3

I made a simple puzzle game in ROBLOX and I've decided to re-make it in AS3.
I've created a grid of buttons with click events, and now I need to change their color when clicked. I've currently got this:
trace("Button clicked:", event.currentTarget.id);
event.currentTarget.graphics.beginFill(0xA00000)
event.currentTarget.graphics.endFill()
the trace prints fine but the color doesn't change (causes no errors either)
The buttons are movie clips with labels inside.
beginFill and endFill are used to control the filled color of drawing commands like drawRect, they don't just change the fill of any arbitrary display object.
To change the color of a display object you can use ColorTransform:
var colorTransform:ColorTransform = new ColorTransform();
colorTransform.color = 0xA00000;
DisplayObject(event.currentTarget).transform.colorTransform = colorTransform;

change button color action script 3

btnPlanet.mouseEnabled = false;
btnPlanet.mouseChildren = false;
i have button and it's called btnPlanet, i want to change button color when they are disabled, but the button contain text, that if i change button color using colorTransform, it make my text dismissed, and filled with color that i use from colorTransform, can i change only color of shape in button without change text color? or make it grayscale at least? thank you, i'm sorry if i have bad grammar english
Apply alpha/colorTransform/whatever to everything EXCEPT text field.
Is it your own button or you're using some kind of component?
If it's your own I bet you have something like background for shape and TextField on top of that.
If it's a component I'm pretty sure you should be able to access it as well.
that's not hard.set instance name of your shape in your button for example myShape. Then write:
btnPlanet.myShape.transform.colorTransform=new ColorTransform(your colortransform settings)

flex - how to set the background color of a spark check box text label?

I have a simple spark mxml check box and I want to change the background color via actionscript. I have searched and tried many suggestions, including using setStyle with 'background-color', 'chromeColor', symbolColor and others like this - the only thing that worked at all is chromeColor, which colored the box but not the text or background:
insUpdatedCB.setStyle('chromeColor','yellow');
I also tried using text format like this:
var myTf:TextFormat = new TextFormat();
myTf.size = 16;
myTf.color = 0xFF0000;
insUpdatedCB.setStyle("textFormat", myTf);
also did not work
how can I set the label/text background color?
If you want to change the background color of the spark checkbox, then you have to apply a custom skin for it. Make a new Custom skin by making a copy of default checkboxSkin for spark checkbox, and then change the background color of the label in the Custom Skin.

setting actionscript textarea color to black

I have some simple actionscript 3 code which compiles and runs without error but doesn't do anything. I just want to change the bacground color to black (or transparent). How can this be done?
myTextArea.setStyle("backgroundColor", "0x000000");
I've tried the color argument without quotes and as "black" but nothing seemes to work.
I can't test it right now, but it should be enough to change your code to:
myTextArea.textField.opaqueBackground = 0x000000;
See this link on SO, if you need more help:
How do I change the colours of a textarea in actionscript?