I'm trying to write a code where my polygon moves from left to right ends of my screen. The main issue I shared is that I'm not able to translate this using fps animator
This is my polygon code:
private void drawface(GL2 gl)
{
gl.glBegin(GL2.GL_POLYGON);
gl.glVertex2f(0, 130);
gl.glVertex2f(120, 130);
gl.glVertex2f(120, 140);
gl.glVertex2f(0, 140);
gl.glEnd();
}
Then this is my display function:
public void display(GLAutoDrawable arg0)
{
final GL2 gl = arg0.getGL().getGL2();
gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
gl.glPushMatrix();
gl.glColor3f(0.5f, 1f, 0.75f);
gl.glTranslatef(t1x, 1, 1);
drawface(gl);
gl.glPopMatrix();
}
I'm updating the int t1x
through a KeyEvent method
public void keyPressed(KeyEvent arg0)
{
int key = arg0.getKeyCode();
if(key == KeyEvent.VK_RIGHT)
{
t1x++;
}
else if(key == KeyEvent.VK_LEFT)
t1x--;
}
But my polygon isn't translating when I click the right arrow key. What should I do ?