How to make an object bounce back and forth? Very basic code?
in
Programming Questions
•
1 month ago
This is what I have so far. I want the rectangle to move back to the other side instead of the just stopping. Another variable needs to be used for this but I don't know how. Could someone help please?
- int xp = 100;
void setup() {
size(300, 300);
noStroke();
}
void draw() {
background(0,0,0);
rect(xp, 100, 10, 10);
xp++;
if (xp > width-10) {
xp = width-10;
}
println(xp);
}
1