hei guys
i'm trying a simple (too simple and stupid) code, bouncing a ball around screen
bounce founction runs correctly.
problem is if i write ball.update() BEFORE gravity and friction ball no moves.
if i write AFTER.. let's ok, runs correctly
WHY?!?!?!?
in update i add.. so if it's zero for first frame no moveing, but second frame i add += gravity.. so i don't understand
i have this in draw:
Code:
// ball.update(); here desn't move.
ball.vy += gravity;
ball.vx *= friction;
ball.vy *= friction;
ball.update(); //here runs ok
checkBounds(ball);
// .....
private void checkBounds(Ball n) {
if(n.x + n.radius > WIDTH) {
n.x = WIDTH - n.radius;
n.vx *= - n.bounce;
}
if(n.x - n.radius < 0) {
n.x = n.radius;
n.vx *= - n.bounce;
}
if(n.y + n.radius > HEIGHT) {
n.y = HEIGHT - n.radius;
n.vy *= - n.bounce;
}
if(n.y - n.radius < 0) {
n.y = n.radius;
n.vy *= - n.bounce;
}
}
and this is Ball class:
Code:public class Ball {
public int radius;
public float x,
y,
vx = 0,
vy = 0,
ax = 0,
ay = 0;
public int color;
public double bounce = 0.6;
public void update() {
vx += ax;
vy += ay;
x += vx;
y += vy;
}
}