Monday, August 26, 2013

Tiled JSON Map Loader Example Code Available

Someone asked me for the source code for the JSON map loader example I created for a video tutorial on using Tiled to export 2d tile maps as JSON map files. Although .tmx is a more popular format, Pygame Subset for Android does not support the xml parser libraries.  Because of this, we can't use the TMX Loader library available on the Pygame site.  Pytmxloader also will not work.  This is unfortunate since the pytmxloader is especially nice.  Although these libraries will work on the desktop.  They will not work on the Android phone.  :-(

At some point, I was planning to write a library for JSON map file loading.  However, I never got around to it.  The code below will work on desktop and mobile phones.  It is for educational purposes only.



JSON Map Loader Lesson Code that works with Tiled maps.




3 comments:

  1. Hello, your tutorials have inspired me, so i will make a game in python :D.

    But, i have a problem... when i try to load a x.json map, my compiler return an error... :(

    builtins.IndexError: cannot fit 'int' into an index-sized integer
    File "C:\Users\***\fishtricity-json-map-loader-lesson-27deb04c9ac7\main.py", line 123, in
    tile = Tile(all_tiles_from_sets[gid -1])

    I searched on google, and I don`t found the answer to my problem.
    Can you help me?

    Best regards, Christian

    ReplyDelete
  2. Christian, try this code here:
    https://github.com/codetricity/json_loader

    ReplyDelete
  3. It looks like you have a really large map, possibly containing a format problem. Try using the map, I put on Github and let me know if you still have that problem.

    ReplyDelete