在 Processing 中实现擦除按钮
Implementing an erase button in Processing
我在 Processing with controlP5 库中创建了一个擦除按钮。擦除按钮的目的是在用鼠标绘制某些东西时擦除(单击擦除按钮时)。类似于画图程序。
非常感谢您!
擦除按钮功能代码:
**boolean erase = false;
void setup(){
}
void draw(){
void keyPressed(){ //there is an error in this line (error on void)
if (keyPressed == true && erase == true) {
background(255);
}
}
}**
keyPressed
should be outside of the draw
function. Also, the codeblock within the keyPressed
函数只有在按下某个键时才会执行,所以您不必自己检查。
boolean erase = false;
void setup(){
}
void draw(){
}
void keyPressed(){
if (erase) {
background(255);
}
}
如果您想检查 draw
函数中是否按下了某个键,那么您可以使用 keyPressed
布尔系统变量。
void draw(){
if (keyPressed && erase) {
background(255);
}
}
此外,如果您想要按下特定的键,您可以使用 key
关键字。
void keyPressed(){
if (key == 'e' && erase) {
background(255);
}
}
我在 Processing with controlP5 库中创建了一个擦除按钮。擦除按钮的目的是在用鼠标绘制某些东西时擦除(单击擦除按钮时)。类似于画图程序。
非常感谢您!
擦除按钮功能代码:
**boolean erase = false;
void setup(){
}
void draw(){
void keyPressed(){ //there is an error in this line (error on void)
if (keyPressed == true && erase == true) {
background(255);
}
}
}**
keyPressed
should be outside of the draw
function. Also, the codeblock within the keyPressed
函数只有在按下某个键时才会执行,所以您不必自己检查。
boolean erase = false;
void setup(){
}
void draw(){
}
void keyPressed(){
if (erase) {
background(255);
}
}
如果您想检查 draw
函数中是否按下了某个键,那么您可以使用 keyPressed
布尔系统变量。
void draw(){
if (keyPressed && erase) {
background(255);
}
}
此外,如果您想要按下特定的键,您可以使用 key
关键字。
void keyPressed(){
if (key == 'e' && erase) {
background(255);
}
}