简体   繁体   English

保存声音首选项Libgdx Android

[英]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 . 问题出在首soundOn使用了不同的名称: soundOnSound The same variable should be used. 应该使用相同的变量。

Also notice that prefs.getBoolean("variable", true) would return true if that variable doesn't exist. 另请注意,如果该变量不存在,则prefs.getBoolean("variable", true)将返回true。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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