我已经阅读了有关scene2d的UI功能的一些教程和文档,但我无法弄清楚外观是如何工作的.我只想要一个TextButton,在按下时会改变颜色.我设法让TextButton的背景改变,但那不是我想要的.它应该没有背景.
如果有人能提供一个如何做到这一点的例子,我将非常感激.这看起来很简单,所以我觉得我在这里遗漏了一些明显的东西.如果涉及皮肤,请以编程方式编写.
谢谢.
事实证明它就像我想的那么简单,当我第一次尝试它时它就没用了.
定义TextButtonStyle时,您可以指定downFontColor文本在按下时所需的颜色.您还可以指定checkedFontColor按下时希望文本切换的颜色.
例:
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);
Run Code Online (Sandbox Code Playgroud)
这将产生一个白色TextButton,按下时会变黑.当释放鼠标/触摸时,它将变为绿色或白色,具体取决于切换的状态.
| 归档时间: |
|
| 查看次数: |
1974 次 |
| 最近记录: |