I'm saving music in libgdx preference, the following code works perfectly but if you enter the settings again you'd see the initial button up regardless if the sound is muted or not.

TextureAtlas buttonsAtlas = new TextureAtlas("ui/dialogButtons.pack");
textButtonStyle.up = skin.getDrawable("music.down");
textButtonStyle.checked = skin.getDrawable("muteMusic.up");
button.addListener(new InputListener() {
 public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
  return true;
 public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
  if (getMusicplaying() == false)
  else playMusic.play();

I tried to do this, it works perfecly but doesn't switch the button, when the user is clicking on it, it only switches when the user closes the dialog

if (getMusicplaying() == true) {
textButtonStyle.up = skin.getDrawable("music.down");
textButtonStyle.down = skin.getDrawable("muteMusic.up");}
if (getMusicplaying() == false) {
  textButtonStyle.up = skin.getDrawable("muteMusic.up");
  textButtonStyle.down = skin.getDrawable("music.down");}
  • \$\begingroup\$ github.com/libgdx/libgdx/wiki/Preferences ? \$\endgroup\$ Feb 8 '17 at 13:18
  • \$\begingroup\$ @realUser404 yes that but what I don't know how to do, is how to save the pressed button state. right now, when I enter the settings, the button shows in its original state, whether it's pressed or not \$\endgroup\$
    – Lynob
    Feb 8 '17 at 13:23

I'm posting this answer since it may help someone, i got it from libgdx forums

if (getMusicplaying() == false)

no need for more code, that's it.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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