You may need a global variable for the x position of the ball.
Bonus
Reset the position of the ball when the mouse is pressed. You can implement the mousePressed() function. p5 will call the function when the mouse is pressed.
// p5 will call this function when the mouse is pressed
function mousePressed() {
// reset x position of ball
}
Hints
You may need a global variable for the
x
position of the ball.Bonus
Reset the position of the ball when the mouse is pressed. You can implement the
mousePressed()
function. p5 will call the function when the mouse is pressed.