java - Put and get a map from Libgdx preferences -
java - Put and get a map from Libgdx preferences -
hey i'm having problems getting info preferences file in libgdx. set map in coords can position stuff, when map preferences file (which gets entire file, not map set in) , can't read coords set in. can keys map no problem, when seek access value map runtime error java.lang.string cannot cast. i've tried different values vector2, , float[] same error
heres code:
public class setsettings { private actor actor; private actor hit; private sprite sprite; private sprite sprite2; private rectangle rect; private boolean customhit = false; private shaperenderer render = new shaperenderer(); array<actor> actors = gamescreen.buttons.stage.getactors(); public setsettings() { setoriginal(); setcustom(); rect = new rectangle(); } public void setoriginal() { learngame.ass.settings.get().clear(); float height = gdx.graphics.getheight(); float width = gdx.graphics.getwidth(); // ui settings java.util.map<string, coords> map = new hashmap<string, coords>(); map.put("hpbar", new coords(width - (learngame.ass.hpbar.getwidth() * 1.02f), height - (height * .076f))); map.put("hpbase", new coords(learngame.ass.hpbar.getx(), learngame.ass.hpbar.gety())); (entry<string, coords> key : map.entryset()) system.out.println(key.getvalue().x); // works fine here } public void setcustom() { java.util.map<string, ?> amap = learngame.ass.settings.get(); (entry<string, ?> key : amap.entryset()) { if (key.getvalue() instanceof coords) { coords coords = (coords) key.getvalue(); float x_value = coords.x; float y_value = coords.y; system.out.println("6" + key.getkey()); system.out.println("" + x_value);// <-----------error here -- java.lang.string cannot cast anything.. } } public class coords { float x; float y; public coords(float x, float y) { this.x = x; this.y = y; } }
}
check api doc - libgdx not back upwards array or collection or objects (other string) in libgdx preferences. if intend utilize libgdx format - consider flattening complex construction associated array of strings or primitive types.
preferences.putfloat("hpbar_x", 123f); preferences.putfloat("hpbar_y", 456f);
java dictionary libgdx preferences
Comments
Post a Comment