Quantcast
Channel: Question and Answer » libgdx
Viewing all articles
Browse latest Browse all 434

LibGDX Json not parsing full file

$
0
0

I’m trying to load a World with different Objects (World Objects and Entities). For that, I want to use Json. For less than two elements this works like a charm. But as I add more elements, some values are skipped on parsing. I’m using LibGDX for my game. Here is my code:

level001.json

{
  "id":1,
  "title":"Broken Home",
  "design":"tomschneider",
  "tiles_x":32,
  "tiles_y":32,
  "objects":[
    {
      "class":"net.sutomaji.space2.helperclasses.LevelStore_Object",
      "object_name":"net.sutomaji.space2.gamelogic.objects.BlackHole",
      "pos_x":10,
      "pos_y":10
    },
    {
      "class":"net.sutomaji.space2.helperclasses.LevelStore_Object",
      "object_name":"net.sutomaji.space2.gamelogic.objects.BlackHole",
      "pos_x":10,
      "pos_y":15
    },
    {
      "class":"net.sutomaji.space2.helperclasses.LevelStore_Object",
      "object_name":"net.sutomaji.space2.gamelogic.objects.SpaceStation",
      "pos_x":0,
      "pos_y":0,
      "i1":0
    },
    {
      "class":"net.sutomaji.space2.helperclasses.LevelStore_Object",
      "object_name":"net.sutomaji.space2.gamelogic.objects.SpaceStation",
      "pos_x":5,
      "pos_y":0,
      "i1":1
    }
  ],
  "entities":[

  ]
}

Excerpt of Level.java

Json json = new Json();
        LevelStore ls = json.fromJson(LevelStore.class, Gdx.files.internal("Worlds/level001.json"));

        System.out.println(json.prettyPrint(ls));

System.out

{
tiles_x: 32,
entities: [],
objects: [
    {
        object_name: net.sutomaji.space2.gamelogic.objects.BlackHole,
        pos_x: 10,
        pos_y: 10
    },
    {
        object_name: net.sutomaji.space2.gamelogic.objects.BlackHole,
        pos_x: 10,
        pos_y: 15
    },
    {
        object_name: net.sutomaji.space2.gamelogic.objects.SpaceStation
    },
    {
        i1: 1,
        object_name: net.sutomaji.space2.gamelogic.objects.SpaceStation,
        pos_x: 5
    }
],
title: "Broken Home",
id: 1,
design: tomschneider,
tiles_y: 32
}

So I am loosing positions (pos_x etc.) and other values (i1) on parsing. I don’t know why. Do you have any ideas?

LibGDX API Json


Viewing all articles
Browse latest Browse all 434

Trending Articles