3
\$\begingroup\$

I am trying to create images for a loading bar in libGDX. I came across the NinePatch class and I was hoping to use it for this loading bar, since stretching images with a plain Texture or Sprite looks terrible. Does anyone have any examples on how to use this class? I have done some searching around and I've gotten it to work but the image I use just comes through as slightly transparent and gray. It just doesn't look like the same image. The actual loading bar itself seems to work fine as I just set the width of the foreground loading image. Here is the code I am using so far...

// Class vars
private NinePatch loadingBackground;
private NinePatch loadingForeground;

...

// In my constructor
loadingBackground = new NinePatch(new Texture(Gdx.files.internal("loadingback.png")), 8, 8, 8, 8);
loadingForeground = new NinePatch(new Texture(Gdx.files.internal("loadingfore.png")), 8, 8, 8, 8);

...

// Drawing
batch.begin();
loadingBackground.draw(batch, x, y, width, height);
loadingForeground.draw(batch, x, y, loadingWidth, height);
batch.end();

I am open to any other suggestions on how I should implement this as well.

\$\endgroup\$
2
  • \$\begingroup\$ Everything you are doing looks fine. Can you post a screenshot of the problem? Try using this ninepatch image, img84.imageshack.us/img84/4407/menuskin.png. \$\endgroup\$ Commented Mar 13, 2012 at 16:22
  • \$\begingroup\$ I got it to work! Though maybe you could explain why haha... I used the image that you suggested and it worked fine so I thought I would play around with the last 4 arguments to the constructor of NinePatch. I see that they stand for left, top, right, bottom. What are these used for exactly? I've looked at the implementation in libGDX source but I'm not quite sure still. \$\endgroup\$ Commented Mar 14, 2012 at 14:08

1 Answer 1

5
\$\begingroup\$

The left, top, right, bottom arguments are the amount of pixel of the segments. For example in: How to NinePatch

This: enter image description here turns to this: enter image description here The left, top, right, bottom are all 8 pixels.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .