处理停止跟踪鼠标x

发布于 2025-02-07 05:27:05 字数 1393 浏览 1 评论 0原文

我正在做游戏的游戏屏幕,我遇到了一个问题。如果屏幕出现了,则如果您将鼠标移动,则由于鼠标X的屏幕将返回游戏中。

我该如何做到这一点,以使鼠标不再从这一点上做出反应?

代码:

int score = 0;
float x_2 = 300;        
float y_0 = 250;  
float y_2 = 650;   
int distanz = 0;
int currentXValue = 0;
int savedXValue = currentXValue;
PImage LilaAuto, GruenAuto, SchwarzAuto, LilaAuto_Main;


void setup() {
    size(450,700);
  
    LilaAuto =loadImage("https://raw.githubusercontent.com/Tf187/Slot-Game-Processing/main/LilaAuto.png");
    LilaAuto_Main =loadImage("https://raw.githubusercontent.com/Tf187/Slot-Game-Processing/main/LilaAuto.png");
}

void draw() {              
            
    background(204);
            
    image(LilaAuto,50,y_0, 100,100);   
    y_0--;
    if(y_0<1) {
        y_0= 650;
    }
         
    fill(204);
    image(LilaAuto_Main,mouseX,y_2, 100,100);  //Auto vom Spieler 
    y_2--;
    if(y_2<1) {
        y_2= 650;
    }
            
    image(LilaAuto,x_2,y_0, 100,100);  
    y_0--;
   
    fill(1);
    textSize(25);
    text("Score:", 10,25);
    text(score,75,25);
           
    float d= dist(mouseX,y_0,x_2,y_2);  //Messung der Distanz
    if(d < 100) {
        score = score+1;
    }  
                     
    if(d < 60) {
        gameOver();
    }
}

void gameOver() {
    score = 0;
    background(120);

    textAlign(CENTER);
    text("GameOver", 250,250); 
}

我提前感谢您的答复

I'm doing the GameOver Screen of my game and I ran into a problem. If the GameOver screen comes up and then if you move the mouse it goes back into the game because of the mouseX.

How can I make it so that the mouseX no longer reacts from this point on?

Code:

int score = 0;
float x_2 = 300;        
float y_0 = 250;  
float y_2 = 650;   
int distanz = 0;
int currentXValue = 0;
int savedXValue = currentXValue;
PImage LilaAuto, GruenAuto, SchwarzAuto, LilaAuto_Main;


void setup() {
    size(450,700);
  
    LilaAuto =loadImage("https://raw.githubusercontent.com/Tf187/Slot-Game-Processing/main/LilaAuto.png");
    LilaAuto_Main =loadImage("https://raw.githubusercontent.com/Tf187/Slot-Game-Processing/main/LilaAuto.png");
}

void draw() {              
            
    background(204);
            
    image(LilaAuto,50,y_0, 100,100);   
    y_0--;
    if(y_0<1) {
        y_0= 650;
    }
         
    fill(204);
    image(LilaAuto_Main,mouseX,y_2, 100,100);  //Auto vom Spieler 
    y_2--;
    if(y_2<1) {
        y_2= 650;
    }
            
    image(LilaAuto,x_2,y_0, 100,100);  
    y_0--;
   
    fill(1);
    textSize(25);
    text("Score:", 10,25);
    text(score,75,25);
           
    float d= dist(mouseX,y_0,x_2,y_2);  //Messung der Distanz
    if(d < 100) {
        score = score+1;
    }  
                     
    if(d < 60) {
        gameOver();
    }
}

void gameOver() {
    score = 0;
    background(120);

    textAlign(CENTER);
    text("GameOver", 250,250); 
}

I thank you in advance for the replies

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情话难免假 2025-02-14 05:27:05

您可以做到这一点的一种方法是使用 noloop()
这样,draw()就不会执行,而不必执行,因为屏幕没有更改。

void gameOver() {
  score = 0;
  background(120);

  textAlign(CENTER);
  text("GameOver", 250,250);
  noLoop();
}

如果您想重新开始循环(因为用户重新启动了游戏),则可以调用 << code> loop() 函数(例如,在keypressed())中,它将像往常一样使draw()再次执行。
这看起来像这样:

void keyPressed() {
  if(key == 'R' || key == 'r') {
    loop();
  }
}

One way you could do this is by using noLoop().
That way, draw() won't be executed, which it doesn't have to, because the screen isn't changing.

void gameOver() {
  score = 0;
  background(120);

  textAlign(CENTER);
  text("GameOver", 250,250);
  noLoop();
}

If you then want to start looping again (because the user restarted the game for example), you can call the loop() function (for example in a keyPressed()), which will makes draw() execute again as usual.
This could look something like this:

void keyPressed() {
  if(key == 'R' || key == 'r') {
    loop();
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文