I would like to know if you can delete something drawn on the canvas. In this example I have 2 circles, circle 1 can move while circle2 is static. I would like that when the circles collide the circle2 disappears. Is it possible to do that?
Thank you.
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 using an equation calculate the distance the problem is that I do not know how to do to erase one of the circles.