I have an OpenGL project that has a collection of GameObjects. I have a thread which is the game loop that iterates over the objects and calls the update method. Additionally, OpenGL has the drawFrame method that iterates over the objects and renders the objects. Finally, I have the onTouchEvent method that is in a third thread that iterates over the objects and calls each objects version of the onTouchEvent method.
That said, when one of my object moves position based off the screen touch, I am getting a ghost image of the object in it's previous location. It is a simple flicker, but very annoying and very obvious. Other objects moving freely (not based off the onTouchEvent) do not have the ghost image of itself trailing, but the object who's position changes when the onTouchEvent method is called, creates a ghost image.
How do I prevent this from happening? I've wrapped both my methods in "synchronized(this)" and it still does not work.
public void drawFrame(GL10 gl)
{
if(renderType == RenderType.r2D)
prepare2DDrawing(gl);
else if(renderType == RenderType.r3D)
prepare3DDrawing(gl);
synchronized(this)
{
camera.draw(gl);
for(GameObject obj:objects)
{
gl.glPushMatrix();
obj.draw(gl);
gl.glPopMatrix();
}
}
}
public void update(float time)
{
cds.testCollisions(objects);
synchronized(this)
{
camera.update(time);
for(GameObject obj:objects)
{
obj.update(time);
}
motions.clear();
}
}
public void onTouchEvent(MotionEvent e)
{
if(touchable == Touchable.TOUCHABLE)
{
synchronized(this)
{
for(GameObject obj:objects)
{
obj.onTouchEvent(e);
}
}
}
}