Я хочу использовать значение из JSon файлаИспользуя значение из JSon файла в Libgdx
Вот файл Json
{
"button" : [
{
"x" : 50.0
},
{
"x" : 150.0
}
]
}
У меня есть следующие классы
(кнопка класса)
public class Button extends Sprite{
float x;
public Button() {
super(new Texture("button.png"));
}
@Override
public void setX(float x) {
this.x = x;
}
}
(класс данных)
public class Data {
public Array<Button> buttons;
public void load() {
buttons = new Array<Button>();
Json json = new Json();
json.setTypeName(null);
json.setUsePrototypes(false);
json.setIgnoreUnknownFields(true);
json.setOutputType(JsonWriter.OutputType.json);
json.fromJson(Data.class, Gdx.files.internal("buttons.json"));
}
}
(Main Class)
public class GameMain extends ApplicationAdapter {
SpriteBatch batch;
Data data;
@Override
public void create() {
batch = new SpriteBatch();
data = new Data();
data.load();
for(Button b : data.buttons) {
b.setX(b.x);
}
}
@Override
public void render() {
Gdx.gl.glClearColor(0, 0, 0, 1f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
for(Button b : data.buttons) {
b.draw(batch);
}
batch.end();
}
}
Я хочу рисовать кнопки в определенных положениях х, которые проводятся в JSon файле но это не дает мне ничего.
Что не так в моем коде?
Любые идеи?
Вы должны вернуться и принять хорошие ответы по старым вопросам. Вы получите репутацию, и люди будут готовы помочь вам. – Tenfour04