Domanda

I have a space with bouncing balls, and when i drag mouse I want a line to be drawn in it so that balls start bouncing from it as well.

  1. I can draw a line consisting of small circles, and add their inside area together, and if a ball intersects this area change direction. This works. The problem is that circles don't produce solid line (as mouseDragged events are fired too rarely), but if I use Line2D instead, it doesn't enclose any area.
  2. In every mouse dragged event I can interpolate data between startPoint and endPoint and draw a circle at obtained x,y. It works, but everything freezes terribly
  3. I can check if ball's covering rectangle contains certain color (and if so, change direction), but again how should it be done -- checking every pixel doesn't seem efficient at all?

Is there a way/best way to deal with it?

È stato utile?

Soluzione

but if I use Line2D instead, it doesn't enclose any area.

Use a Path2D or a Polygon that has a (very thin) width. It will look like a line, but have an area.

Then use it in the code seen in this answer.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top