I am having trouble with the animation in my simple pong game. It seems that i doesn’t clear the screen completly before painting the next frame. This causes the ball to appear at two places at once.
The display code looks like this:
//can’t move objects when this is true
displayCalled=true;
GL gl = drawable.getGL();
GLU glu = drawable.getGLU();
/** Clear the colour buffer */
gl.glClear( GL.GL_COLOR_BUFFER_BIT ); //why?
ball.display( gl, glu );
leftPadd.display( gl, glu );
rightPadd.display( gl, glu );
upperWall.display( gl, glu );
lowerWall.display( gl, glu );
displayCalled=false;
Another thread controlls the moving of the objects and if my code is correct it can’t update the objects while painting is done. All the objects have a nearly identical display method:
public void display( GL gl, GLU gl ){
gl.glColor3f( 1.0f, 1.0f, 1.0f );
gl.glBegin( GL.GL_QUADS );
gl.glVertex2i( xpos, ypos );
gl.glVertex2i( xpos+xsize, ypos );
gl.glVertex2i( xpos+xsize, ypos+ysize );
gl.glVertex2i( xpos, ypos+ysize );
gl.glEnd();
}
I don’t have a clue of what is wrong( a good indication that there is something I have misunderstood ). Any help is appreciated.
oyse
I forgot to mention that I use the Animator class to handle the rendering loop