android - Storing booleans in Preferences -


im struggling grasp how store/read booleans preferences in libgdx. im using them if user have bought item, boolean should turn true , stored true until different boolean turned true , first 1 turned false. hope im exlpaining myself in understandable way.

this i´ve done:

screen make purchase , presses button make change:

purcscreen implements screen { changestone1.addlistener(new changelistener() {          @override         public void changed(changeevent event, actor actor) {             ss.prefs.getboolean("stone1", true);             game.setscreen(ss);         }      }); 

and screen object have purchased should drawn depending on wether or not boolean true/false:

mainscreen implements screen { public boolean stone1, stone2 public mainscreen { stone1 = prefs.getboolean("stone1"); stone2 = prefs.getboolean("stone2"); if(stone1){     setstone1();      }     if(stone2){         setstone2();     } show() { if(stone1) {         setstone2();         prefs.putboolean("stone1", true);         prefs.putboolean("stone2", false); } if(stone2) {         setstone2();         prefs.putboolean("stone1", false);         prefs.putboolean("stone2", true); } btnsave.addlistener(new changelistener() { @override public void changed(changeevent event, actor actor) { prefs.putboolean("stone1", stone1); prefs.putboolean("stone2", stone2); prefs.flush(); } 

with code, booleans arn´t stored. stone2´s image/object drawn. click savebutton , re-enter screen original stone1 object drawn again.

get preferences object framework (make sure same name when reading , writing)

preferences prefs = gdx.app.getpreferences("my preferences"); 

save boolean prefs object:

prefs.putboolean("soundon", true); prefs.flush(); 

read boolean prefs object:

prefs.getboolean("soundon"); 

reference wiki:

https://github.com/libgdx/libgdx/wiki/preferences


Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -