Possible Duplicate:
How do I apply gravity to my bouncing ball application?
I have a ball class that bounces off the ground.
Here is a portion of my code:
public void update(){
yPos += ySpeed;
ySpeed += gravity;
if(yPos > BOTTOM_OF_SCREEN){
ySpeed *= -1;
}
}
The problem with this code is that when I have a ball in mid air, it bounces higher than it started, and keeps bouncing higher and higher, but I want it to bounce to the same height that it started with.