Hi i'm using the ImmediateModeRenderer renderer = new ImmediateModeRenderer10(); to render a line with the next block

renderer.begin(matrix, GL10.GL_LINES);
    renderer.color(color.r, color.g, color.b, color.a);
    renderer.vertex(x0, y0, 0);
    renderer.color(color.r, color.g, color.b, color.a);
    renderer.vertex(x1, y1, 0);

But know I want to erase some part of that line when I drag the mouse over it, are there any ideas ?


1 Answer 1


If you want to erase part of the line when you drag the mouse over it, there's two ways:

The cheating way

Have a background with a solid color, and have the mouse create lines/shapes of that color over your existing line. The player will be given the illusion of the line having been erased, though this approach might fall down on its face if you're trying to do anything reasonably complex.

You could also have a background with a texture, and give it an identical foreground (which is completely transparent, and mouse clicks add to its transparency mask).

The non-cheating way

Detect where the mouse has intersected the line and break the line in two pieces, leaving you drawing multiple lines after multiple erasures (all parallel).

To detect this, each frame, you should determine the vector between the mouse's current position and its position in the previous frame and determine if the line of this vector intersects with the line you've drawn. If so, split the line on the intersection point into two lines, then shorten both slightly (otherwise your erasing will appear to do nothing, since both lines are still perfectly joined).

  • \$\begingroup\$ Great idea for the second option, I'm going to try it, thanks \$\endgroup\$
    – magorich
    Commented Apr 18, 2012 at 22:04
  • \$\begingroup\$ Perfect it worked great \$\endgroup\$
    – magorich
    Commented Apr 19, 2012 at 23:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .