title: LibGDX Accelerometer - Android
body: <p>I write code for moving player left and right, also when player moves left it has one animation, and when he moves right he has another animation.</p>
  
  <p>This is the code (dt is deltaTime):</p>
  
  <pre><code>    // Moving player desktop
      if (Gdx.input.isKeyPressed(Keys.A)) // Left
      {
          position.x -= speed * dt;
          currentFrame =  animation.getKeyFrame(4 + (int) stateTime);
      } 
      else if (Gdx.input.isKeyPressed(Keys.D)) // Right
      {
          position.x += speed * dt;
          currentFrame = animation.getKeyFrame(8 + (int) stateTime);
      }
      else // Normal
      {
          currentFrame = animation.getKeyFrame(12);
      }
  </code></pre>
  
  <p>So I also want to move player (on mobile devices) with accelerometer. I done that, but now I don't know how to check if player is moving left or right to give him different animations</p>
  
  <p>My code:</p>
  
  <pre><code>    // Moving player android
      // position.x -= Gdx.input.getAccelerometerX() * speed * dt;
  
      if( PLAYER MOVING LEFT)
      {
          // Player moving left....
          currentFrame =  animation.getKeyFrame(4 + (int) stateTime);
      }
      else if (PLAYER MOVING RIGHT)
      {
          // Player moving right....
          currentFrame =  animation.getKeyFrame(8 + (int) stateTime);
      }
      else
          currentFrame = animation.getKeyFrame(12);
  </code></pre>