I want to create a function that can generate two balls that rise at different speeds. I used the parameters of the speed in which it rises called “change” and another parameter of its x coordinates called “x”, so that they don’t originate from the same place.
If I call the function, it works, and the ball moves according to the speed I set it to. However, if I call it twice, two balls are generated but both move at the speed that I call it with the second time. In this case, two balls were generated at x coordinates 150 and 450. The first ball was supposed to move at speed y-10, and the second ball at speed y-5, but both are moving at y-5.
Therefore, they move, but the whole purpose of the code which is making it change doesn’t work. Can someone help me make it change?
void setup(){
size(600,600);
}
float y = 600;
void risingball(float change, float x){
noStroke();
fill(30,0,30);
y = y-change;
ellipse(x,y, 50,50);
}
void draw(){
background(255);
risingball(10, 450);
risingball(5, 250);
}