Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
    
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. –  Luis Estrada Mar 13 '12 at 16:22
    
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. –  Alex_Hyzer_Kenoyer Mar 14 '12 at 14:08

1 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.