title: How to do "map chunks", like terraria or minecraft maps?
body: <p>Due to performance issues, I have to cut my maps into chunks.
  I manage the maps in this way:</p>
  
  <pre><code>listMap[x][y] = new Tile (x,y);
  </code></pre>
  
  <p>I tried in vain to cut this list for several "chunk" to avoid loading all the map because the fps are not very high with large map. And yet, when I update or Draw I do it with a little tile range. Here is how I proceed:</p>
  
  <pre><code>foreach (List&lt;Tile&gt; list in listMap)
  {
      foreach (Tile leTile in list)
      {
          if ((leTile.Position.X &lt; screenWidth + hero.Pos.X) &amp;&amp;
              (leTile.Position.X &gt; hero.Pos.X - tileSize) &amp;&amp;
              (leTile.Position.Y &lt; screenHeight + hero.Pos.Y) &amp;&amp;
              (leTile.Position.Y &gt; hero.Pos.Y - tileSize)
          )
          {
              leTile.Draw(spriteBatch, gameTime);        
          }
      }
  }
  </code></pre>
  
  <p>(and the same thing, for the update method).</p>
  
  <p>So I try to learn with games like minecraft or terraria, and any two manages maps much larger than mine, without the slightest drop of fps. And apparently, they load "chunks".</p>
  
  <p>What I would like to understand is how to cut my list in Chunk, and how to display depending on the position of my character. I try many things without success.</p>
  
  <p>Thank you in advance for putting me on the right track!</p>
  
  <p>Ps : Again, sorry for my English :'(
  Pps : I'm not an experimented developer ;)</p>
  
  <p>edit : </p>
  
  <p>Thanks to IVlad, I gain 10 fps changing just the loops like this :</p>
  
  <pre><code>for (int x = (int)(hero.Pos.X) / tileSize; x &lt; (hero.Pos.X / tileSize) + (int)(screenWidth/tileSize); x++)
  {
      for (int y = (int)(hero.Pos.Y) / tileSize; y &lt; (hero.Pos.Y / tileSize) + (int)(screenHeight / tileSize); y++)
      {
          if (x &gt;= 0 &amp;&amp; y &gt;= 0 &amp;&amp; x &lt;= tileXMax &amp;&amp; y &lt;= tileYMax ) {
              grille[x][y].Draw(spriteBatch, gameTime);
          }
      }
  }
  </code></pre>
  
  <p>Despite that, the fps are still low and depend on the size of the map instead of the number of visible tiles.</p>