Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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);
renderer.end();

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

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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).

share|improve this answer
    
Great idea for the second option, I'm going to try it, thanks –  magorich Apr 18 '12 at 22:04
    
Perfect it worked great –  magorich Apr 19 '12 at 23:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.