Tiled Maps for XNA – Full support for the Tiled Map XML specification!

UPDATE: There is a newer, better version from here. Thanks, Zach Musgrave!

So yesterday I came across a very basic loader for Tiled Maps (*.tmx) made with the Tiled Map Editor. It only supported the basics–Tileset loading and Layer rendering–so I took it upon myself to complete the loader by adding support for the rest of the features that were left out;

-added ProhibitDtd = false, so you don’t need to remove the doctype line after each time you edit the map.
-changed everything to use SortedLists for named referencing–so much easier
-added objectgroups
-added movable and resizable objects
-added object images
-added meta property support to maps, layers, object groups and objects
-added support for non-binary encoded layer data
-added layer and object group transparency

I created a simple demo to show off some of the features. You should see a partially transparent object with a resized image of Ness (Earthbound) on top of a partially transparent layer of grass with the words “Tile Maps Rule” written in rock with a pulsating opacity. Use the arrow keys to move Ness around. All objects and object groups can have their X and Y coordinates set dynamically, so you can do cool stuff like parallax clouds drifting overhead.

Download the Tiled Maps Loader

Be Sociable, Share!

You can leave a response, or trackback from your own site.
  • Pingback: Tiled map loader for XNA « luminance

  • michi

    Hello

    I didn’t get the transparency working…are you sure you implemented it?

    Ich made a map with one layer und in the tileset i can see that there are some transparents tiles, so i choose the right color while i imported the tileset

    but when i use this map in your example, than the tiles are purple and not trancparency

    can you help me?

    thx

  • http://www.nerdculture.org Stephen Belanger

    That’s part of the tileset file, not the map file. I don’t have any support for tileset files yet. I might do that later.

  • michi

    hmm

    what about this new feature: “-added layer and object group transparency” ?

    hmm in the map file there is a node e.g. “trans=ff00ff” in the same line where the tileset source is.
    .-= michi´s last blog ..GMX Lottozahlen =-.

  • http://www.nerdculture.org Stephen Belanger

    That’s referring to the opacity setting that can be set on each layer or object group using the slider above the layer list.

  • michi

    ok now i got it.

    hmm, maybe i make a transparentcy extension.

    so that the color which is defined in the editor as trancparent

  • http://asdasdad Max

    How optimized is the code? Did anyone benchmark this yet? Can it handle a 9000×9000 32×32 map?

  • http://www.nerdculture.org Stephen Belanger

    I didn’t really do much in the way of performance testing, so it’s probably not very optimized. Nick Gravelyn expanded on the concept here;
    http://blog.nickgravelyn.com/2010/03/know-when-to-be-lazy/

    Admittedly, I haven’t really taken a close look at what he did. Apparently he rewrote it all to use a custom pipeline–what I made was parsing the XML at runtime, which could probably get slow on larger maps.

  • http://www.facebook.com/sleptlate Zach Musgrave

    Just thought you should know, I updated this library to support tile rotation and mirroring  in the newest version of Tiled.  Thanks for writing it!

    http://gamedev.sleptlate.org/blog/277-rotation-and-mirroring-flipping-with-tiled-map-editor-and-xna/

  • http://www.facebook.com/sleptlate Zach Musgrave

    I also added support for margin and spacing in tile sets.  Download link is the same as before.

    http://gamedev.sleptlate.org/blog/316-more-camera-work-and-padded-tilesets/

  • http://twitter.com/ZachMusgrave Zach Musgrave

    Just thought you should know I finally got around to throwing my updated version onto GitHub: https://github.com/zachmu/tiled-xna

Bad Behavior has blocked 2491 access attempts in the last 7 days.