处理停止跟踪鼠标x
我正在做游戏的游戏屏幕,我遇到了一个问题。如果屏幕出现了,则如果您将鼠标移动,则由于鼠标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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以做到这一点的一种方法是使用
noloop()
。这样,
draw()
就不会执行,而不必执行,因为屏幕没有更改。如果您想重新开始循环(因为用户重新启动了游戏),则可以调用 << code> loop() 函数(例如,在
keypressed()
)中,它将像往常一样使draw()
再次执行。这看起来像这样:
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.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 akeyPressed()
), which will makesdraw()
execute again as usual.This could look something like this: