title: c++ 2D TileMap Render optimization
body: <p>I have a question about 2D TileMap Optimization.</p>
  
  <p>I rendered the Tilemap but the speed is too slow (Frame-rate == 50)</p>
  
  <p>I think I can specify tiles to be rendered. So instead of rendering all tiles, just render tiles on Screen (Device).</p>
  
  <p>This is my current method.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code> //Lower Layer
    for(int y = 0; y &lt; Height; ++y)
    {
     for(int x = 0; x &lt; Width; ++x)
     {
      //if the tile index number is -1, then this is null tile (non drawing) 
      if( Layer1[y][x] != -1)
      {
       // this EPN_CheckCollision() Function is the AABB Collision Function. 
       // if there 2 Rect value's are collide , then return true. 
  
       if(EPN_CheckCollision( EPN_Rect(EPN_Pos(x*32, y*32)-CharacterPos) , EPN_Rect(0-32,0-32,1024+32,768+32) ) )
       {
       //EPN_Pos structure is consist of (float PosX , float PosY)
       EPN_Pos TilePos = EPN_Pos(x * 32, y * 32)-CharacterPos;
  
       //EPN_Rect structure is consist of below members
       //float Top X
       //float Top Y
       //float BottomX (not Width)
       //float BottomY (not Height)
       EPN_Rect TileRect = EPN_Rect( Layer1[y][x] % 8 * 32, Layer1[y][x] / 8 * 32, Layer1[y][x] % 8 * 32 + 32, Layer1[y][x] / 8 * 32+32);
  
         //Blt is Texture render function. 
                       // 2nd Parameter is Render Pos and 3rd parameter is Render Texture's Rect.
       pEPN_TI-&gt;Blt("MapTileset",  TilePos, TileRect );
       }
      }
     }</code></pre>
  </div>
  </div>
  </p>
  
  <p>This is my TileMapRender Method. </p>
  
  <p>( I use EPN Engine made by directX which is Unknown. So I annotated my code)</p>
  
  <p>I rendered the tilemap that collides with the DeviceScreen ( 1024 * 768 , but for margin)
   because I want to render visible tilemap on screen (I do not render tiles out of device screen).
   So I Check the AABB Collision each tile and (1024, 768) device Screen, now I only render necessary tiles.
   But I think this method has a problem, that it does not render out of screen tiles. 
  For statement also repeat all <em>maptiles;</em> what a inefficient method...
   Maybe my games frame-rate problem is in this method. So may I ask STACK OVERFLOW how I could do this?</p>
  
  <p>Is there another ways to optimize tilemap rendering?
   Give me some tips please.</p>
  
  <p>P.S</p>
  
  <p>I'm sorry about my knotty question.</p>
  
  <p>Please excuse my English ability.</p>