title: Android - Rotating background image by fixed screen position
body: <p>I am attempting to create simple top down side scrolling style app in android.  Basically an image sits in the bottom center of the screen which does not move.  A background image behind this will move based on the tilt of the device.</p>
  
  <p>If I don't move (translate) the image and I rotate it based upon the first images center point, the background image rotates correctly around this point.  If I translate the background image at all however, the rotation is no longer accurate.  It seems that the rotation is applied based on the images Top, Left not the screen top left, so if I translate the image by 100 units down the screen, it now rotates 100 units below where I want it to.</p>
  
  <p>Basically I am looking for a way to rotate an image no matter where it is located on the screen by a fixed position on the screen that never changes.  Hopefully this will create the illusion that the image at the bottom of the screen is moving when in fact it is the background that is moving.  Thanks.</p>
  
  <p>Here's some simple code snippets of what Im doing, not sure if it really helps:</p>
  
  <p>m_X &amp; m_Y are variables holding the tilt of the device</p>
  
  <p>That horrible hard coded value of 264, 628 is the location of my animating character at the bottom of the screen.  (what I want the background image to rotate around no matter where it has translated itself to)</p>
  
  <pre><code>Update Function:
  protected void Update(float a_GameTime)
  {
      super.Update(a_GameTime);
  
      m_CharacterAnimator.Update(a_GameTime);             
  
      if ((m_CurrentCharacterDirection.contains(LEFT) || m_CurrentCharacterDirection.contains(RIGHT)) &amp;&amp; (m_X &gt; 1.0f || m_X &lt; -1.0f))
      {
          m_BackgroundWorldMatrix.preRotate(m_X * .05f, 264, 628);
      }
      if ((m_CurrentCharacterDirection.contains(FORWARD) || m_CurrentCharacterDirection.contains(BACKWARD)) &amp;&amp; (m_Y &gt; 1.0f || m_Y &lt; -1.0f))
      {
          m_BackgroundWorldMatrix.postTranslate(0.0f, m_Y * -0.25f);
      }       
  }
  
  Draw Function:
  protected void Draw(Canvas a_Canvas)
  {
      super.Draw(a_Canvas);
  
      a_Canvas.drawBitmap(m_Background, m_BackgroundWorldMatrix, null);//, m_BackgroundWorldMatrix, null);
  
      // Draw the animating Character
      m_CharacterAnimator.Draw(a_Canvas);
  }
  </code></pre>