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?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How can I create this custom Bottom Navigation on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
Solved the problem by using the setBackground(Drawable drawable) method for the table. I created an anonymous class of drawable, and created a sprite inside of that which is rendered in the draw method of the anonymous class.
I see that the problem has already been solved, but there are others asking to see the code and I can't comment yet.
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
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).
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.
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.
Backup:
https://github.com/ronrihoo/libGDX-Table-Background-Color
You can do it like this:
Remember to call dispose() on the texture and on the pixmap. `
For those of you who have asked for some sample code, here's a simple implementation. (I've just discovered BaseDrawable, and it's proved to be wonderful for situations like this !)
Use it like this: