title: Flash performance for game dev: native render VS BitmapData framebuffer
body: <p>I develop a 2D shooter game with <em>lots of objects</em> and <em>aggressive scrolling</em>.</p>
  
  <p><strong>QUESTION:</strong> which way is better?</p>
  
  <p>CHOICE 1 - use native Flash rendering:</p>
  
  <ul>
  <li>derive game objects from Bitmap, use existing x, y, width, height, bitmapData</li>
  <li>add all objects as children UIComponent.addChild(...) to sccreen</li>
  <li>clip visible area using "scrollRect"</li>
  </ul>
  
  <p>CHOICE 2 - write custom rendering using "bitmap + copyPixels"</p>
  
  <ul>
  <li>use own game object with x, y, width, height, bitmapData</li>
  <li>add a Bitmap to a screen, take bitmapData from it</li>
  <li>redraw every ENTER_FRAME: bitmapData.lock(), iterate over game objects and copyPixels() into bitmapData, then bitmapData.unlock()</li>
  <li>custom clipping: do not render out of screen objects</li>
  </ul>
  
  <p>Here in this <a href="https://stackoverflow.com/questions/989471/vsync-in-flex-flash-as3">question</a> some people complain that "bitmap + copyPixels()" is slow.</p>
  
  <p><strong>EXPERIMENT:</strong> I have implemented both techniques:</p>
  
  <ul>
  <li><a href="http://sites.google.com/site/oshyshko/framebuffer_vs_nativerender/main_1_more_creeps.swf?attredirects=0" rel="nofollow noreferrer">main_1.swf</a> - native</li>
  <li><a href="http://sites.google.com/site/oshyshko/framebuffer_vs_nativerender/main_2_more_creeps.swf?attredirects=0" rel="nofollow noreferrer">main_2.swf</a> - custom</li>
  </ul>
  
  <p>Please, try them and tell which one is better (faster, smoother, eats less CPU).</p>
  
  <p>Wait until there will be <em>at least 250 enemies</em> (counter above the screen).<br>
  <strong>UPDATE:</strong> Try to open Task Manager (or $top) and see overall CPU usage</p>
  
  <p><strong>UPDATE 2:</strong> I've changed the code, now creeps spawn much faster.</p>