简体   繁体   中英

Saving Sound Preference Libgdx Android

Trying to make an image for sound control. Need to make an image turn music on and off. And save it so that the music doesn't restart every time you go back to the main menu. Trying to use preferences any help would be appreciated.

private Preferences prefs;
private boolean spref = true;


prefs = Gdx.app.getPreferences("Soundpref");
prefs.putBoolean("soundOn", true);
intro = Gdx.audio.newMusic(Gdx.files.internal("Sound/intro.wav"));

  if (prefs.getBoolean("Sound", true))
    {
        intro.play();
    }

and this is my image listener

   if (menuPanel.spressed && spref == true) {
       intro.stop();
       prefs.flush();
       prefs.putBoolean("Sound", false);
       spref = false;
   }

The problem is with different names in prefs: soundOn and Sound . The same variable should be used.

Also notice that prefs.getBoolean("variable", true) would return true if that variable doesn't exist.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM