JSON Files - GameDevWeek/CodeBase GitHub Wiki

JSON is a text-based format to store structured content. We are using it to create maps of images, animations, sounds, particle effects, ... (also to preload them).

This section will cover the basic files used at almost every GDW. You can of course create and load new ones.

Simple Maps

These files use the simple map format:

  • sounds.json
  • particles.json
  • music.json
  • images.json
  • fonts.json

Example:

{
    "menu": "data/music/menu.ogg",
    "game": "data/music/game.ogg",
    "credits": "data/music/credits.ogg"
}

As you can see, the format is a simple "key": "value", enclosed in curly braces, separated by comma. (Notice the last key-value pair line does not end with a comma)

Value is always a filename, while key is the name which is used in the game to access it.

Code

This would be used in code like this:

assetManager.loadAssetList("data/json/music.json", Music.class, null);

The last paramter can be used to configure the loader, tho not all loaders are configurable.

Configurable Maps

These files use the configurable map format:

  • animations.json

Example:

{
    "walking": {
        "filename": "data/animations/walking.png",
        "frames" : 1,
        "frameDuration": [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1],
        "playType" : "LOOP",
        "columns": 7,
        "rows" : 1
    },
    "ball": {
        "filename": "data/animations/ball.png",
        "frames" : 2,
        "frameDuration": [0.5, 0.5],
        "playType" : "LOOP",
        "columns": 2,
...
}

This format is used if each file loaded needs to be configured individually. As you can see, the value-part is now a map. The "filename" attribute tells the loader which file to load, while the other parameters depend on the loader being used (in this case, an AnimationLoader).

Code

This would be used in code like this:

assetManager.loadAssetListWithParam("data/json/animations.json", AnimationExtended.class,
        AnimationExtendedLoader.AnimationExtendedParameter.class);

Entities JSON

See EntityFactory for a detailed description

SceneAnimator JSON

For credits, intro/outro animations, See SceneAnimator for a detailed description

Custom JSON formats

You can create your own custom JSON loader with just a few lines of code. See the JSON Example for more a simple example.

It would be nice to have more detailed examples and explanations here, but my time is limited, so sometime in the future.