Trying to render a tmx map

I am relatively new to MonoGame and C#. I just can’t seem to figure out how to render the map (.tmx) file, using either TiledSharp or tmx-mapper-pcl. I sort of know what I need to do, but I would need that tiny bit code which shows what to do after the map file has been loaded (var map = new TmxMap(“someMap.tmx”);). I would also need to make it work with Farseer Physics Engine and I have no idea how to go about that. I’m trying to make a 2D side scroller, so I think its not that hard, but I could be wrong.

I have been googling for hours, with different search terms, but I can’t find anything that would work with either one of those two libs.

If there are other ways/libs to render a map made with Tiled, do tell.

Thanks in advance,
Temeez, Windows 7, MonoGame 3.3.

Did you ever figure the issue out? I’m trying to figure out how to get the content processor to work with the new content pipeline.

Edit: lol, logged in with the wrong account…

Oh, totally forgot this. :smiley:

Yes, I actually managed to do what I wanted to. Hope this helps.

Level.Map = new TmxMap("Content/Levels/map.tmx");
_tileset = content.Load<Texture2D>("Textures/" + _map.Tilesets[0].Name);


for (var i = 0; i < _map.Layers[0].Tiles.Count; i++)
    int gid = _map.Layers[0].Tiles[i].Gid;
    // Empty tile, do nothing
    if (gid == 0) {

    else {
        int tileFrame = gid - 1;
        int row = tileFrame / (_tileset.Height / _tileHeight);

        float x = (i % _map.Width) * _map.TileWidth;
        float y = (float)Math.Floor(i / (double)_map.Width) * _map.TileHeight;

        Rectangle tilesetRec = new Rectangle(_tileWidth * tileFrame, _tileHeight * row, 32, 32);

        spriteBatch.Draw(_tileset, new Rectangle((int)x, (int)y, 32, 32), tilesetRec, Color.White);

Did you get it to build into the new content pipeline tool that they put in? If you did, then how? Also, which did you use, TiledSharp or tmx-mapper-pcl?

Oh, forgot to mention, I used TiledSharp and I didn’t compile the .tmx file at all. I just put the file to the project and set it to “copy if newer” and then Level.Map = new TmxMap(“Content/Levels/map.tmx”);

YES!!! I got it working… kinda sorta lol. Where did you put the texture2D property? I put it in the TmxImage class, is there a better place to put it?

Also is what is _tileset.Height supposed to be? I’m thinking its the height of the tile but that doesn’t make sense since you have _tileHeight.

Its the height of the tileset image of course :smiley: which is 256x256 in my case.

I really don’t know if there is a better place for the Texture2D.

For row you are dividing the the tileset height like so _tileset.Height / _tileHeight, and if im understanding you correctly they are the same thing. Was it meant to be something else? Also, did this work for multiple layers for you? When i implemented it, only 1 tile was being drawn as the entire map.

I haven’t got the time to test if it works with multiple rows, but I took that logic from somewhere here (I think, it has been a while)

I made this, mostly for when I forget or lose the for loop xD

Check the code Kagraxx, the multiple row drawing works now!

I don’t know if this helps or not but the latest version of Tiled allows you to export your TMX to a .png image, which may make things easier for you…