LibGDX not able to use NinePatchDrawable as a background to table, when I created it from textureRegion that was flipped

132 Views Asked by At

so here is something I wanted to do

`TextureRegion region = new TextureRegion(new Texture("path to the file"));
 region.flip(false, true);
 NinePatch patch = new NinePatch(region, left, right, up, down);
 NinePatchDrawable drawable = new NinePatchDrawable(patch);
 Table table = new Table();
 table.setBackground(drawable);
 table.add(someLabel);
`

when I add table to the stage I can see the label,but there is no background, same works if textureRegion is not flipped, can someone explain to me why?

1

There are 1 best solutions below

0
Sebastian On

That happens because TextureRegion.flip() alters the u/v and u2/v2 coordinates. Creating a NinePatch from a TextureRegion the way you did it only used the texture and the x/y coodinates from that TextureRegion. The u/v/u2/v2 information is lost at this point.

It looks like the NinePatch(TextureRegion... patches) constructor probably preserves that information but I didn't try it.