title: Drawing a tiled map with Monogame
body: <p>I've been trying to implement a function that lets me draw the tiles inside a tiled file (.tmx). I've looked around and found a kind of working piece of code but it <a href="http://i.stack.imgur.com/MMDka.png" rel="nofollow">stretches out the tiles</a>.<br>
  This is the code I found and edited a bit:</p>
  
  <pre><code>private void DrawLayer(int index, SpriteBatch batch) {
          for (var i = 0; i &lt; Map.Layers[index].Tiles.Count; i++) {
              //Get the identification of the tile
              int gid = Map.Layers[index].Tiles[i].Gid;
  
              // Empty tile, do nothing
              if (gid == 0) { }
              else {
                  int tileFrame = gid - 1 ;
                  int column = tileFrame % (tileset.Width / tileWidth);
                  int row = tileFrame / (tileset.Height / tileHeight);
  
                  float x = (i % Map.Width) * Map.TileWidth;
                  float y = (float)Math.Floor(i / (double)Map.Width) * Map.TileHeight;
  
                  //Put all the data together in a new rectangle
                  Rectangle tilesetRec = new Rectangle(tileWidth * column, tileHeight * row, tileWidth, tileHeight);
  
                  //Draw the tile that is within the tilesetRec
                  batch.Draw(tileset, new Rectangle((int)x, (int)y, tileWidth, tileHeight), tilesetRec, Color.White);
              }
          }
      }
  </code></pre>