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