Jump to content
  • Advertisement
Sign in to follow this  
Whiskydog

[libGdx] How to set up Button background without stretching it (through ninepatch)?

This topic is 652 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, so I'm making an UI and I can't figure out how to have a (Text) Button with a background independent of the stretching that the button itself may apply. I tried adding the image to it (since Button extends Table) but didn't work. I'm aware I could just put the background as the ninepatch but it gets horribly stretched since... well... it'd be a ninepatch. The button's Table.setBackground() method doesn't work either...

 

I also thought of using an ImageButton but apparently that's not what it'd be used for (from Scene2D.ui's wiki):
 

Note that ImageButton extends Button, which already has a background drawable for the up, down, and checked states. ImageButton is only needed when it is desired to have a drawable (such as an icon) on top of the button background.

 

I'm really at a loss on how to solve this particular problem, help will be appreciated  :)

Share this post


Link to post
Share on other sites
Advertisement

TextButtonStyle is what you need. Set the style.up with the drawable you want and that's it all

 

I'm already using styles.

 

For the style's drawable you (usually) want a Ninepatch (since the width's dependant of the text u'll put in the button) and having a ninepatch with a background on it will look bad when stretched since that's the point of the ninepatch. If I don't use a ninepatch however I'd have fixed size buttons? What if the text I'll put in the button is larger (wider) than the button itself? That's the problem I'm trying to solve: have 'dynamic' buttons (as in sizable to whatever u want) but with a background (without having it stretched).

 

In any case, thanks for replying!  :)

Share this post


Link to post
Share on other sites

You can set a background with a Drawable image create with Texture(LinearFilter) so this way you can reduce the "stretched". Create the size of the texture with the largest size you use in your buttons.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!