如何通过单击鼠标右键来停止 Processing Draw 循环?
How can I stop the Processing Draw loop by click mouse right button?
我要设置游戏
当我按下“s”键,然后开始游戏。
我按下鼠标右键后,
它将重置并停止游戏。
现在的问题是当我点击鼠标右键时,
变量“游戏”应设置为假,
但当我释放鼠标按钮时它仍然是真的。
谁能帮帮我?谢谢
boolean game = false;
void setup() {
size(640, 480);
}
void draw() {
background(200, 200, 200);
if (key=='s') game=true;
println("1::" + game);
if (game==true) {
// gaming...
if (mousePressed && mouseButton == RIGHT) {
// I want to reset the game...
game=false;
println("2 after pressed right mouse button::" + game);
}
println("3 why still run the code here after I press mouse right button? ");
}
}
void mouseDragged()
{
if (game==true) {
// the dragging game...
print("3:: dragging" + game);
}
}
使用 mousePressed()
函数代替 mousePressed
变量:
The mousePressed()
function is called once after every time a mouse button is pressed
void draw() {
background(200, 200, 200);
// DELETE
//if (key=='s') game=true;
//println("1::" + game);
if (game==true) {
// gaming...
// DELETE
//if (mousePressed && mouseButton == RIGHT) {
// game=false;
// println("2 after pressed right mouse button::" + game);
//}
println("3 why still run the code here after I press mouse right button? ");
}
}
void keyPressed() {
if (!game and key == 's') {
game = true;
println("1::" + game);
}
}
void mousePressed() {
if (game && mouseButton == RIGHT) {
game = false;
println("2 after pressed right mouse button::" + game);
}
}
我要设置游戏
当我按下“s”键,然后开始游戏。 我按下鼠标右键后, 它将重置并停止游戏。 现在的问题是当我点击鼠标右键时, 变量“游戏”应设置为假, 但当我释放鼠标按钮时它仍然是真的。
谁能帮帮我?谢谢
boolean game = false;
void setup() {
size(640, 480);
}
void draw() {
background(200, 200, 200);
if (key=='s') game=true;
println("1::" + game);
if (game==true) {
// gaming...
if (mousePressed && mouseButton == RIGHT) {
// I want to reset the game...
game=false;
println("2 after pressed right mouse button::" + game);
}
println("3 why still run the code here after I press mouse right button? ");
}
}
void mouseDragged()
{
if (game==true) {
// the dragging game...
print("3:: dragging" + game);
}
}
使用 mousePressed()
函数代替 mousePressed
变量:
The
mousePressed()
function is called once after every time a mouse button is pressed
void draw() {
background(200, 200, 200);
// DELETE
//if (key=='s') game=true;
//println("1::" + game);
if (game==true) {
// gaming...
// DELETE
//if (mousePressed && mouseButton == RIGHT) {
// game=false;
// println("2 after pressed right mouse button::" + game);
//}
println("3 why still run the code here after I press mouse right button? ");
}
}
void keyPressed() {
if (!game and key == 's') {
game = true;
println("1::" + game);
}
}
void mousePressed() {
if (game && mouseButton == RIGHT) {
game = false;
println("2 after pressed right mouse button::" + game);
}
}