按下鼠标并出现一个文本时,我需要代码方面的帮助

时间:2019-04-13 04:44:56

标签: boolean mouseevent keycode

在我的学校课堂上,我们正在做一个非常简单的游戏,是或否的问题,但是我不知道何时按下屏幕上的特定位置(将是一个按钮)。我将使用rect作为按钮,并且我是Java语言的新手。

我试图将x和y混合在一起,并且尝试使用另一种方法来更改x和y。

//**This is my code**//


  //**The first button for the cat**//
  rect(5, 225, 50, 50);
  text("Yes", 10, 298);

  //**The second button for the cat**//
  rect(145, 226, 50, 50);
  text("No", 160, 297);

  if ((mousePressed==true)&&(mouseX<=27)&&(mouseY<=248)) {
    textSize(10);
    text("Your right", 67, 260);
  }

  if ((mousePressed==true)&&(mouseX<=153)&&(mouseY<=256)) {
    textSize(10);
    text("Your wrong", 67, 260);
  }

  if ((mousePressed==true)&&(mouseX<229)&&(mouseY<229)) {
    textSize(20);
    text("Correct", 345, 254);
  }

  if ((mousePressed==true)&&(mouseX<493)&&(mouseY<231)) {
    textSize(20);
    text("Incorrect", 345, 254);
  }
}

void mousePressed(){
  //**Clears the screen**//
 clear(); 
}

我的目标是尝试在按下按钮时显示一个,这样我只能在按下按钮时看到一个。另一个也一样。

0 个答案:

没有答案