mouse motion listener only in one direction

后端 未结 4 939
粉色の甜心
粉色の甜心 2020-12-07 00:28

i have been working on mouse motion listener in Java couldn\'t sort it out completely because i want the object to move towards the direction where ever on the screen the mo

4条回答
  •  余生分开走
    2020-12-07 00:46

    From here:

    public void mouseMoved(MouseEvent e){
     xpos=getX();
     if(xpos<0){polyrot--;}
     else if(xpos>0){polyrot++;}
     repaint();
     break;
    }
    

    It seems you update only the xpos. You should update also the variable ypos. You might want to do it with something like this:

    ypos=e.getY();
    if (this.ypos<0){
     this.polyrot--;
    }else if (this.ypos>0) {
     this.polyrot++;
    }
    this.repaint();
    

提交回复
热议问题