title: My Scrolling Bitmap Canvas is too slow to use
body: <p>I am learning to program for the Android. I've made a couple of basic games, but for learning I'd like to make a car driving game. The simplest way I thought of doing this was to keep the car in the middle of the screen and scroll the background to give the illusion of movement.</p>
  
  <p>As an experiment to figure out the engine, I created a 2048x1200 Bitmap which I load from a PNG. This will be the map. I then create a new bitmap of 1024x600 cropped from the map which I display on screen. I do this as getWidth() &amp; getHeight() give these dimensions. I take a different crop each time based on movement to show on screen.</p>
  
  <p>Unfortunately I find this too slow to use. The car would have to move at a snails pace if I wanted it to be smooth. I get about 18fps.</p>
  
  <p>I am using <a href="http://blorb.tumblr.com/post/236799414/simple-java-android-game-loop" rel="nofollow noreferrer">James Daniello's Simple Game Loop</a></p>
  
  <p>I also read the following stack overflow article which says to keep the object creation out of the main loop as much as possible, which I am doing as best I can.<br>
  <a href="https://stackoverflow.com/questions/1430741/how-to-draw-lots-of-bitmaps-on-screen-in-an-android-game-without-slow-performance">How to draw lots of bitmaps on screen in an Android game without slow performance</a></p>
  
  <p>Also of use was this article by Romain Guy on keeping the Bitmap as the same format as the screen to stop it having to be transformed to be displayed on the screen, which is very costly.<br>
  <a href="http://www.curious-creature.org/2010/12/08/bitmap-quality-banding-and-dithering/" rel="nofollow noreferrer">Bitmap quality, banding and dithering</a></p>
  
  <p>I'd like to figure out the best I can achieve with Canvas and Bitmaps before I move on to OpenGL. Am I at the limitations, or should I do something differently? I find I get 18fps when just scrolling the map 1px at a time for smooth scrolling.</p>
  
  <pre><code>private Bitmap track;
  private Bitmap visible;
  private Point position;
  private int fps = 0;
  private long lastFpsTime = 0;
  private int fpsCount = 0;
  Paint pText;
  
  public void Draw(Canvas c){
      visible = Bitmap.createBitmap(track, position.x + 512, position.y + 300, 512, 300);
      position.x++;
      c.drawBitmap(visible, 0,0, null);
      c.drawText("FPS: " + fps, 10, 10, pText);
  }
  
  public void Init(Resources resources) {
      // Load Map from track1.png
      track = Bitmap.createBitmap(2048, 1200, Bitmap.Config.RGB_565);
      Bitmap track1 = BitmapFactory.decodeResource(resources, R.drawable.track1);
      track = track1.copy(Bitmap.Config.RGB_565, true);
      position = new Point(0,0);
  
      //Setup the Text Paint Object
      pText = new Paint();
      pText.setColor(Color.WHITE);
      pText.setStyle(Style.FILL_AND_STROKE);
  }
  
  public void Update() {
      fpsCount++;
  
      if (System.currentTimeMillis() - lastFpsTime &gt;= 1000){
          lastFpsTime = System.currentTimeMillis();
          fps = fpsCount;
          fpsCount = 0;
      }
  }
  </code></pre>