increasing counter on key click by ONE !
in
Programming Questions
•
4 months ago
Hi again,
sorry i am new to processing and programming.
I want to increase a counter +1 if i hit a key, for example the "b" key on the keyboard.
The Problem is when i hit the key the counter doesn't stop by increasing one,
it counts on and on.
thats what my code is :
int count;
void setup() {
size(400, 400);
stroke(255);
background(192, 64, 0);
}
// Click on the window to give it focus,
// and press the 'B' key.
void draw() {
if (keyPressed == true) {
if (key == 'b' || key == 'B') {
count++;
}
} else {
count=count;
}
switch(count) {
case 0:
println("Zero"); // Does not execute
rect(25, 25, 50, 50);
break;
case 1:
println("One"); // Prints "One"
rect(25, 25, 80, 80);
break;
case 2:
println("two"); // Prints "One"
rect(25, 25, 100, 100);
break;
case 3:
println("three"); // Prints "One"
rect(25, 25, 150, 150);
break;
}
}
It would be realy nice if someone could fix me that !
sorry i am new to processing and programming.
I want to increase a counter +1 if i hit a key, for example the "b" key on the keyboard.
The Problem is when i hit the key the counter doesn't stop by increasing one,
it counts on and on.
thats what my code is :
int count;
void setup() {
size(400, 400);
stroke(255);
background(192, 64, 0);
}
// Click on the window to give it focus,
// and press the 'B' key.
void draw() {
if (keyPressed == true) {
if (key == 'b' || key == 'B') {
count++;
}
} else {
count=count;
}
switch(count) {
case 0:
println("Zero"); // Does not execute
rect(25, 25, 50, 50);
break;
case 1:
println("One"); // Prints "One"
rect(25, 25, 80, 80);
break;
case 2:
println("two"); // Prints "One"
rect(25, 25, 100, 100);
break;
case 3:
println("three"); // Prints "One"
rect(25, 25, 150, 150);
break;
}
}
It would be realy nice if someone could fix me that !
1