creating a random circle that can be clicked on like a button

后端 未结 2 1455
一个人的身影
一个人的身影 2021-01-27 08:02

so here is my predicament i cannot seem to find this anywhere on the internet. My question is simple. I am creating a game app for android. The game will generate random circles

2条回答
  •  醉梦人生
    2021-01-27 08:36

    from what i've understood you are trying to make circles that you are drawing randomly clickable by the user, well this is pretty easy actually first you have to save the random position of the new circle in an integer variable then make a condition that will be controlled through an onToutchEvent

    @Override
        public boolean onTouchEvent (MotionEvent event) {
    
            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN : 
                    xPos = event.getX();
                    yPos = event.getY();
                    invalidate(); 
                    break;
            }
    
            return true;
    
        }
    

提交回复
热议问题