Time based animitaion

I have a sprite that the user controlls and he moves using time based movement. My question is how can i make the actual animation frames time based. He moves at a good rate but the animation is extreamly fast. Here is the code that draws the sprite. It is called every time the display meathod is called(about 30 fps).



public void drawHero(int heroXPosition, int heroYPosition, int direction,
                  boolean move) {
            
            
            
            
            if (move) {
                        
                        if (animationPosition < 7 ) {
                              
                              animationPosition++;
                        } else {
                              animationPosition = 0;
                        }
                        
                  } 
                  
                  else {
                        animationPosition = 0;
                  }
            
            gl.glEnable(GL.GL_TEXTURE_2D);
            gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_MODULATE);
            gl.glDisable(GL.GL_LIGHTING);
            if (direction == 0) {
                  gl.glBindTexture(GL.GL_TEXTURE_2D,
                              heroUpTextureId[animationPosition]);
            }
            if (direction == 1) {
                  gl.glBindTexture(GL.GL_TEXTURE_2D,
                              heroDownTextureId[animationPosition]);
            }
            if (direction == 2) {
                  gl.glBindTexture(GL.GL_TEXTURE_2D,
                              heroLeftTextureId[animationPosition]);
            }
            if (direction == 3) {
                  gl.glBindTexture(GL.GL_TEXTURE_2D,
                              heroRightTextureId[animationPosition]);
            }
            gl.glBegin(GL.GL_QUADS);
            gl.glTexCoord2f(0.0f, 0.0f);
            gl.glVertex2f((heroXPosition), (heroYPosition));
            gl.glTexCoord2f(1.0f, 0.0f);
            gl.glVertex2f(((heroXPosition) + 128), (heroYPosition));
            gl.glTexCoord2f(1.0f, 1.0f);
            gl.glVertex2f(((heroXPosition) + 128), ((heroYPosition) + 128));
            gl.glTexCoord2f(0.0f, 1.0f);
            gl.glVertex2f((heroXPosition), ((heroYPosition) + 128));
            gl.glEnd();
            gl.glDisable(GL.GL_TEXTURE_2D);
      }

Thanks

[quote]I have a sprite that the user controlls and he moves using time based movement. My question is how can i make the actual animation frames time based.
[/quote]
To “bind” your animation to the real world time, you should first ask yourself, what is the desired duration of each frame in the animation. Let’s say we want an animation where the frame is changed every 100ms (1/10 of a second), and there are 20 frames altogether:


// The current real world time, in milliseconds
long time = System.currentTimeMillis();

// The current animation frame ((time / duration) mod totalnumberofframes)
int animationFrame = (int) ((time / 100) % 20);

Hope this helps a bit