I currently have a button thats an input to my arduino and whenever I push it, it is suppose to add a ball. I was able to figure out how the position (on/off) value of the button to processing. But I cant figure out how to write a code that adds an ellipse to the game. Ive tried if statements and all it does is add a ball but when the button is not pressed the ball goes away.
You need to use a boolean to set a condition permanently.
Your Code :
//this will only draw the ellipse if/while the Button is pressed/held
if (buttonPressed == true) {
ellipse(x, y, w, h);
}
How it‘s supposed to be :
boolean showEllipse = false;
if (buttonPressed) {
showEllipse = true;
}
if (showEllipse) {
ellipse(x, y, w, h);
}
As for adding ellipses, you can do that with a for loop, where the condition is < numberOfBalls, which will be increased each time you want to add a ball.
Inside of this for loop you‘ll have to draw each ellipse.
You might also want to have an array for the position/extent of your ellipses.