I would like to know if it is possible to delete something drawn on the canvas. In this example I have 2 circles, circle 1 can move while circle 2 is static. I would like that when the circles collide the circle2 disappears. Is it possible to do that?
Thanks.
public class Juego extends View implements View.OnTouchListener {
int x = 100;
int y = 100;
int radio = 100;
Paint paint;
int x2, y2;
public Juego(Context context, AttributeSet attrs) {
super(context, attrs);
this.setOnTouchListener(this);
setFocusable(true);
paint = new Paint();
}
public void onDraw(Canvas canvas){
Paint paint1 = new Paint();
paint1.setColor(Color.GREEN);
canvas.drawCircle(x, y, radio, paint);
x2= canvas.getWidth()/2;
y2=canvas.getHeight()/2;
canvas.drawCircle(x2, y2, radio, paint1);
double dist = Math.sqrt(Math.pow((x2 - x), 2) + Math.pow((y2 - y), 2));
if (dist < radio + radio){
}
}
public boolean onTouch(View view,MotionEvent event){
x = (int)event.getX();
y = (int)event.getY();
invalidate();
return true;
}
}
I have the 2 circles and by means of an equation I calculated the distance. The problem is that I don't know how to delete one of the circles.
Sorry for the previous comment. Nothing is understood. If what you want is for it to disappear completely, I would add a boolean. public class Play extends View implements View.OnTouchListener {
}
With a condition. If(circle 1 does not touch circle 2) circle 2 is drawn. When circle 1 touches circle 2, circle 2 will not be drawn.