title: Tile based map lags using a for-loop to draw, android game programming
body: <p>I would like to know if anybody can help me with a better method of drawing a Tile map for my android game.</p>
  
  <p>Currently, I use a for loop to draw the required Bitmaps to the screen but when doing this for the amount of tiles I need to render at once (enough to cover the screen and a bit more), when the map scrolls, you can notice the map become jolty with its movement, because of the for loop having to loop through all the tiles. The tiles are drawn simular to this:</p>
  
  <pre><code>for(int i = 0; i &lt; 170; i++) {  
          canvas.drawBitmap(bitmap, x + i * bitmap.getWidth(), y, null);  
      }
  </code></pre>
  
  <p>The method I am currently using uses a few bitmaps to save memory, and draws them in different locations. </p>
  
  <p>A different method i can think of to draw the map would be to create a larger Bitmap from the tiles and move the position of that larger bitmap to create movement. The problem with this is that is does require lots of memory and gets out of memory errors.</p>
  
  <p>So, i need to try and find out a method of drawing multiple tiles preferably without the use of a for-loop (I believe the for-loop is causing the jolty, un-smooth movement of the map).</p>
  
  <p>For more details just ask, thanks.</p>