skin fonts

Quick update, a few important changes to scene2d.ui, for those brave enough to use it before it has solidified.

1) BitmapFonts are now described as:

Instead of the old way:

This makes the internal of the skin JSON loading simpler and more powerful. If a JSON value is a string where normally an object is expected, it is interpreted as a reference to a resource.

2) There is now an OrderedMap and the Json class uses it, so order from your JSON is preserved. The order of the resources in the skin JSON is important. Eg, TextureRegions should be before BitmapFonts because BitmapFont will use a TextureRegion with the same name, allowing the font to be packed in the skin texture.

3) Button used to have setText and try to manage a Label if it didn’t already have one. Now a Button is just a table with an optional background region or nine patch with 3 states: up, down, and checked. There is now TextButton that is a Button with a Label, and ImageButton that is a button with an Image.

ninepatch tinting

NinePatch now has a color which it uses to tint the texture regions when drawing. This is useful for filling areas of the screen with a solid color, using tinting for down and disabled states for buttons, etc. The new functionality does not even break existing scne2d skin JSON, imagine that! The various supported nine patch declarations now looks like this:

The first two forms are the old format, which is still supported so your skins won’t break. The next two allow us to have more than just a list of regions, and these examples show how to tint the nine patch a color. The color field is optional of course. The last example shows that colors (and in fact any other object) can be defined inline.

For use with scene2d, it is convenient to include a nine patch that is a single white pixel, then tint it any color you like. This is useful to give a table a solid background color. The tinting can be defined in the skin, as shown above, or the white 1×1 pixel nine patch can be retrieved from the skin and the tinting set programmatically:

This is using a copy constructor to copy the nine patch from the skin and set a different color. If you just got the white nine patch from the skin and called setColor, it would change the color of the white nine patch everywhere it was used in your app.