Skip to content Skip to sidebar Skip to footer

Trying To Get The X, Y Coordinate Of Each Random Circle That Is Drawn In Android

I am making a game that will create random circles on the screen. The circles created randomly will have the value red or green. My question is that I would like to be able to not

Solution 1:

What you are calling randomWidth and randomheight actually are the x and y cordinates of your circle. this is the methods sign:

canvas.drawCircle(x, y, radius, paint);

To check if the user clicked inside the circle you can do this:

public boolean onTouch(View v, MotionEvent event) {
   int x = (int)event.getX();
   int y = (int)event.getY();
   if(isInsideCircle(x, y)){
      //Do your things here
   }
   returntrue;
}

private boolean isInsideCircle(int x, int y){
  if (((x - center_x)^2 + (y - center_y)^2) < radius^2)
    returntrue;
  returnfalse;    
}

Post a Comment for "Trying To Get The X, Y Coordinate Of Each Random Circle That Is Drawn In Android"