We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, I would like to control two different interactions through keyPressed in one switch. One is a rotating windmill which can be switch on and off. The other 4 different circles added or removed through keyPressed. The interactions work individually but not when I combine them in a switch. Is there a better way to do that? Thank you for your help.
boolean rotation1 = false, rotation2 = false; // boolean windmill
boolean drawingFirstEllipse, drawingSecondEllipse, drawingThirdEllipse, drawingFourthEllipse = true;
void draw(){
//windmill ON/OFF
...
}
// draw cloud
if(drawingFirstEllipse) ellipse(50, 50, 10, 10);
if(drawingSecondEllipse) ellipse(50, 50, 70, 10);
if(drawingThirdEllipse) ellipse(50, 50, 130, 10);
if(drawingFourthEllipse) ellipse(50, 50, 190, 10);
}
void keyPressed() {
switch(interaction){
case 1:
// windmill ON/OFF
if (key == '1')
rotation1 = !rotation1;
else if (key == '2')
rotation2 = !rotation2;
// cloud behavior
case 2:
if (key == '3')
drawingFirstEllipse = !drawingFirstEllipse;
break;
case 3:
if (key == '4')
drawingSecondEllipse = !drawingSecondEllipse;
break;
case 4:
if (key == '5')
drawingThirdEllipse = !drawingThirdEllipse;
break;
case 5:
if (key == '6')
drawingFourthEllipse = !drawingFourthEllipse;
break;
default:
if (key == '7')
interaction = 2;
}
Answers
Why have you got an undeclared variable for -> interaction?
Please post a compilable code! [..]
Sorry, now I post you the entire code. Thank you.
switch
, it's gonnadefault
toif (key == '7')
7
is pressed, it's gonnacase 2:
forif (key == '3')
.drawingFirstEllipse = !drawingFirstEllipse;
.