title: How do i keep track of elapsed time in Java's 3rd party API "LibGDX"?
body: <p>I am making a game in which the player ("Bob") moves vertically and collects coins continuously. If the player does not manage to collect any coins for 5 seconds, "Bob" begins to fall. As time continues to count down, he will fall more quickly. </p>
  
  <p>My question is this: <strong>How does one keep track of elapsed time in a LibGDX (Java) application?</strong></p>
  
  <p>Sample code follows.</p>
  
  <pre><code>public void update (float deltaTime)
  {
  `velocity.add(accel.x * deltaTime,accel.y*deltaTime);`
  
      position.add(velocity.x * deltaTime, velocity.y * deltaTime);
      bounds.x = position.x - bounds.width / 2;
      bounds.y = position.y - bounds.height / 2;
      if (velocity.y &gt; 0 &amp;&amp; state == BOB_COLLECT_COINE)
      {
       if (state== BOB_STATE_JUMP)
        {
         state = BOB_STATE_Increase;
          stateTime = 0;
      }
      else
      {
      if(state != BOB_STATE_JUMP)
       {
        state = BOB_STATE_JUMP;//BOB_STATE_JUMP
         stateTime = 0;
  
          }
        }
      }
  
       if (velocity.y &lt; 0 &amp;&amp; state != BOB_COLLECT_COINE)
        {
         if (state != BOB_STATE_FALL) {
         state = BOB_STATE_FALL;
          stateTime = 0;
        }
       }
         if (position.x &lt; 0) position.x = World.WORLD_WIDTH;
      if (position.x &gt; World.WORLD_WIDTH) position.x = 0;
  
        stateTime += deltaTime;
       }
  
  
  
       public void hitSquirrel ()
         {
         velocity.set(0, 0);
         state = BOB_COLLECT_COINE;s
         stateTime = 0;
         }  
  
       public void collectCoine()
        {
  
        state = BOB_COLLECT_COINE;
         velocity.y = BOB_JUMP_VELOCITY *1.5f;
          stateTime = 0;
         }
  </code></pre>
  
  <p>and call the collectmethod in World class in upate Bob as --</p>
  
  <pre><code>  private void updateBob(float deltaTime, float accelX)
      {
  
    diff = collidetime-System.currentTimeMillis();
    if (bob.state != Bob.BOB_COLLECT_COINE &amp;&amp; diff&gt;2000) //bob.position.y &lt;= 0.5f)
      {
       bob.hitSquirrel();
     }
  </code></pre>