首页 > 解决方案 > How can I track where my mouse goes and then if it goes beyond 400 pixels then print "you lose"?

问题描述

When my mouse goes beyond 400 pixels, it needs to print "you lose".

I have already tried the code below. Nothing happens

void setup() {
   size(800, 600);
   if (mouseX > 400) {
     print("game over");
   }
}   

Nothing happens.

标签: processingmouse

解决方案


setup()功能只运行一次,就在程序第一次启动时。

如果您希望您的代码继续运行,请考虑将其放入draw()函数中,该函数每秒运行 60 次。

void setup() {
   size(800, 600);
}

void draw() {
   if (mouseX > 400) {
     print("game over");
   }
} 

推荐阅读