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.


Leave a Reply

Your email address will not be published.