问题描述
我正在创建一个菜单(就像那只飞扬的小鸟一样,当您死亡时,它会弹出播放屏幕).我创建了一个扩展表的类,并且想要将表的背景设置为白色.有办法吗?
I am creating a menu (like the one is flappy bird, when you die it pops up over the play screen). I created a class that extends table, and I want to set the background of the table to white. Is there a way to do this?
推荐答案
我看到问题已经解决,但是还有其他人要求查看代码,但我无法发表评论.
I see that the problem has already been solved, but there are others asking to see the code and I can't comment yet.
这是类似解决方案的实现,除了将提供一个可供实例化的类(以便可以在以后轻松更改Table背景颜色):
Here's an implementation of a similar solution, with the exception that a class will be made available for instantiation (so that the Table background color can be changed later easily):
https://www.snip2code.com/Snippet/2615417
BackgroundColor backgroundColor = new BackgroundColor("white_color_texture.png");
backgroundColor.setColor(2, 179, 228, 255); // r, g, b, a
table.setBackground(backgroundColor);
因此,通过从您的项目资源中为构造函数提供白色PNG的文件名,来创建任意BackgroundColor类的实例(如上所示)(例如@ Tenfour04在上面的注释中提到的内容).
So, create an instance of the arbitrary BackgroundColor class (linked above) by giving the constructor the filename of a white PNG from your project resources (like what @Tenfour04 has mentioned in the comment above).
如果您不熟悉后一部分,请参阅下面的回购链接,可以在其中找到此类PNG文件的示例.
If you're not familiar with the latter part, then see the repo linked below, where an example of such PNG file can be found.
现在使用实例的setColor(red,green,blue,alpha)方法,然后使用setBackground(Drawable drawable)方法将实例传递到libGDX表.
Now use the instance's setColor(red, green, blue, alpha) method, then pass the instance to the libGDX Table using the setBackground(Drawable drawable) method.
这并不意味着是所有解决方案的完美解决方案-根据需要进行修改.
This is not meant to be a perfect solution for all — modify as needed.
备份:
https://github.com/ronrihoo/libGDX-Table-Background-Color
这篇关于Libgdx | Scene2d |设置表格的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!