CSV Map and collisions?

Hey everyone, I’m using tiled to create a 2D RPG. I dont haave much experience with parsing files so being able to read from a .csv is a big step for me.

Now i dont know how to create collisions to be used in my game. So hopefully someone could help me out, I assume its with a new layer and the rectangle select tool but theres a small problem… Even with another tile layer with overlapping tiles im faced with a problem where my .csv contains only 1 layer.

I thought it would atleast export the different layer types in 1 file but i guess not? Maybe i misssed something?

If not, What is the best map filetype to use? Im using C# And monogame to create my game. I would like to stick to .csv if possible, So hopefully someone could help me with that. If not, Please suggest a better map type and i will attempt to use it!

Thanks in advance!


I am not sure how exactly the CSV export works for tiled, but in general
CSV means comma seperated values. So it is a format to express table data

The format is mainly for the people who are too lazy to parse the fully
supported map files (like tmx, json, lua) I think :slight_smile:

So if you want to make use of all features of tiled better stick to tmx,
json or the lua format. Those are considered to always match tiled


  • Sent from mobile. Please excuse shortness and typing errors. (Might be
    sent delayed too)


I really urge you to learn how to read from an xml file (same as tmx really, you can just rename the map to “yourMap.xml” and it will function as an xml file), it’s going to make a lot of things easier for you in the long run.

Perhaps I can help you getting started. Keep in mind though that the examples I will give you is based on a normal XNA project (I can’t stand MonoGame until they have implemented a proper content pipeline, it’s simply horrible as it is now, unfortunately), but if you can get your MonoGame project to properly load xml files for you (I couldn’t, haha), then the code below should work the same regardless.

Let’s say we have a .tmx/.xml map looking like this:

<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" orientation="orthogonal" renderorder="left-down" width="2" height="2" tilewidth="32" tileheight="32" nextobjectid="1">
   <tileset firstgid="1" name="sea_000" tilewidth="32" tileheight="32">
      <image source="Tilesets/sea_000.png" width="256" height="192"/>
   <layer name="Ground" width="2" height="2">
         <tile gid="1"/>
         <tile gid="1"/>
         <tile gid="1"/>
         <tile gid="1"/>

We can then read from this file by using the following C# code:

XmlReaderSettings settings = new XmlReaderSettings();
settings.DtdProcessing = DtdProcessing.Parse;
using (XmlReader reader = XmlReader.Create("yourMap.xml", settings))
   while (reader.Read())
      switch (reader.NodeType)
         case XmlNodeType.Element:
            switch (reader.Name)
               case "map":
                  // Do something based on the information given
                  // inside the <map> starting tag, such as reading
                  // width and height (in tiles) of the map
                  width = int.Parse(reader.GetAttribute("width"));
                  height = int.Parse(reader.GetAttribute("height"));
               case "layer":
                  // This is where you would want to do something
                  // based on which layer we're currently reading.
                  // You could for example read the name of the 
                  // layer and do something based on that name.
                  layerName = reader.GetAttribute("name");
               case "tile":
                  // Notice that I skipped a case for the "data" tag,
                  // this will make the reader just skip to the next row.
                  // This is where you would want to get the gid of the
                  // tile currently being read.
                  gid = int.Parse(reader.GetAttribute("gid"));

Of course, it would probably be a good idea if you try and learn the basics of xml before you try and implement something based on my example, but it should serve as a good base, I think. :stuck_out_tongue:

Regarding collisions, this can be done in a lot of different ways. I’m not going to get into depth on this right now, but feel free to ask and I will try and help you further.

Oh, and I’m sorry for not giving you any advice on using .csv! I simply don’t know how I would approach using a .csv or .txt file since I wouldn’t personally ever use anything but .xml for my maps. :frowning:

Note that there is no need to rename the file to .xml. The original .tmx
file works too.

  • Sent from mobile. Please excuse shortness and typing errors. (Might be
    sent delayed too)