Reputation: 8584
The image below needs to be stretched just over the grey area vertically. The rest of the image should expand equally horizontally so it fills up the screen.
So I have setup the ninepatch as 0, 0, 158, 28
(a, b, c, d). And when I use this as a Table
background this is the result.
It looks to me the image is "just" filling the screen and ignoring the ninepatch split completely.
My world size is 140 wide and 250 high atm. And the image is 733 wide. Could this be the problem? I never had issues with ninepatch on small images.
This is how I setup the image:
winTable = new Table(skin);
winTable.background("winpanel");
winTable.setFillParent(true);
stage.addActor(winTable);
//And this is how the image in the atlas is specified
winpanel
rotate: false
xy: 0, 298
size: 733, 203
split: 0, 0, 158, 28
orig: 733, 203
offset: 0, 0
index: -1
I tried to play with the numbers to get a good result without success. I also tried to create a NinePatch
manually and use that in a Image
but I am getting the same result. Now I'm wondering if it's even possible to do what I want and maybe I need to split the banner from the rest of the image. But then the two images should line up perfectly.
Upvotes: 2
Views: 377
Reputation: 1517
This is the method I use for ninepatches and it works for me. I don't have the "split" line in my atlas, so you may not need to use it with this.
TextureRegion region = skin.getRegion("winpanel");
NinePatch patch = new NinePatch(region, 0, 0, 158, 28);
NinePatchDrawable drawable = new NinePatchDrawable(patch);
winTable.setBackground(drawable);
EDIT: I just noticed you mentioned that your world size is 140 wide and the image is 733 wide...this is very likely your problem because it is squeezing the width of the image to fit your table. Open the image in a photo editor and scale the image so that the width exactly same as the width that you want it to appear in your game. Then try the ninepatch with new values for your new images size and see if it works.
Upvotes: 1