title: Android bitmap animation
body: <p>I am adding bitmap animations into my simple 2D android game engine(if you can call it one yet.. :D) and I am facing problem of cycling through frames at pre defined FPS/rate.</p>
  
  <p>What I have done for now is simply use System to get currentTimeMillis and use it as reference but I am pretty sure that's not the best decision.. I was thinking I could pass current frame to the drawing method and use that to the drawing method.</p>
  
  <p>Currently I have object that you get the drawable from and I use it on renderer like this:</p>
  
  <pre><code>canvas.drawBitmap(animation.getDrawable(), (int)x, (int)y, null);
  </code></pre>
  
  <p>and getDrawable() returns current frame of the animation or the only frame if its still image and heres the code</p>
  
  <pre><code>        if(frames.size() &gt; 1) {
              long current = System.currentTimeMillis();
              if (currentFrame == frames.size() - 1 &amp;&amp; frameDirection == 1) {
                  frameDirection = -1;
              } else if (currentFrame == 0 &amp;&amp; frameDirection == -1) {
                  frameDirection = 1;
              }
              if ((current - lastFrame) &gt; delay) {
                  currentFrame += frameDirection;
                  lastFrame = current;
              }
          }
          return frames.get(currentFrame);
  </code></pre>
  
  <p>and in my eyes that just looks so bad and unefficient.. What can I do about this? Is the only way to go passing current frame to getDrawable or how should this be done?</p>